博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2773 Happy 2006
阅读量:7051 次
发布时间:2019-06-28

本文共 810 字,大约阅读时间需要 2 分钟。

这是一个找规律的题;

例如: 12互质的数有 1 5 7 11 (12)13 17 19 22 (24) 25

我们可以看到一个循环节;

View Code
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int num[1000024];int Gcd( int a , int b ){ return b == 0 ? a : Gcd( b , a%b ); }int main( ){ int n,k; while( scanf( "%d %d",&n,&k )==2 ) { int cnt = 0; for( int i = 1 ;i <= n ; i ++ ) { if( Gcd( i , n ) == 1 ) { num[++cnt] = i; } } if( cnt >= k ) printf( "%d\n",num[k] ); else { long long t = (k - 1)/ cnt ; int tt = k % cnt ; if( tt==0 ) tt = cnt; printf( "%lld\n",t*n + num[tt] ); } } //system( "pause" ); return 0;}

 

转载于:https://www.cnblogs.com/bo-tao/archive/2012/07/14/2591726.html

你可能感兴趣的文章
一个docker镜像中的目录删除不了问题
查看>>
LAMP(1) 在VirtualBox里安装Ubuntu Server
查看>>
并行开发-线程同步机制
查看>>
python之路(转载)
查看>>
Five Errors Customers Make When Patching E-Business Suite 12[3]
查看>>
iOS - AVPlayer 音视频播放
查看>>
动态规划——Freedom Trail
查看>>
springmvc学习笔记
查看>>
LRU算法的设计
查看>>
文本操作 $(..).text() $(..).html() $(..).val()最后一种主要用于input
查看>>
Ocelot(四)- 认证与授权
查看>>
css选择器30种
查看>>
K-means算法[聚类算法]
查看>>
函数中的可变参数
查看>>
清除windows系统垃圾文件简易脚本(bat)
查看>>
Java 之switch语句
查看>>
焊盘的制作
查看>>
Finalize 和 Dispose 的分析
查看>>
从一道题看线程安全--牛客网Java基础题
查看>>
简单验证码业务
查看>>