poj3358
来源:互联网 发布:什么录屏软件好 编辑:程序博客网 时间:2024/05/21 20:22
#include<iostream>#include<cstdlib>#include<cstdio>using namespace std;typedef long long LL;LL pow(LL a,LL p,LL m){LL d=1,t=a;while(p>0){ if(p&1==1){ d=(d*t)%m; } t=(t*t)%m; p=p>>1;}return d;}int enlerFun(int n){int count = n; for(int i=2;i<=n;i++){ if(n%i==0){ count=count-count/i; while(n%i==0){n=n/i;} } } return count;}LL gcd(LL a,LL b){ return b==0?a : gcd(b,a%b);}int main(){ int t=0; LL p,q,d,time,yue,minyue; //minyue最小的能使公式成立的约数 while( ~ scanf("%I64d/%I64d",&p,&q) ){ d=gcd(p,q);p/=d;q/=d; //化简分子和分母 //printf("%I64d %I64d",p,q); time=1; while( (q&1)==0 ){ //注意添加括弧 time++; q=q>>1; } //time就是起始位置3088601 yue=enlerFun(q); minyue=yue; //printf("%d\n",minyue); for(int i=1;i*i<=yue;i++){ if(yue%i==0){ if(pow(2,i,q)==1 && i<minyue){minyue=i;} //符合公式,大擂台找最小 if(pow(2,yue/i,q)==1 && (yue/i)<minyue){minyue=(yue/i);} } //printf("***%d\n",minyue); } printf("Case #%d: %d,",++t,time); printf("%d\n",minyue); }//whilereturn 0;}
0 0
- poj3358
- POJ3358
- poj3358 Period of an Infinite Binary Expansion
- poj3358数论(欧拉定理)
- POJ3358 Period of an Infinite Binary Expansion
- poj3358 Period of an Infinite Binary Expansion
- 欧拉函数+费马定理 POJ3358
- POJ3358 Period of an Infinite Binary Expansion
- poj3358 Period of an Infinite Binary Expansion 数论有难度
- 【数论】poj3358 Period of an Infinite Binary Expansion
- POJ3358 Period of an Infinite Binary Expansion【欧拉函数】
- POJ3358 Period of an Infinite Binary Expansion 欧拉定理应用
- 【POJ3358】Period of an Infinite Binary Expansion-欧拉定理+数论好题
- 【引】swift是什么?
- 如何更好的认识自己?
- Linux cat命令的使用案例
- 04python_senior
- 图片垂直居中
- poj3358
- JVM_Bind问题的解决方案
- 【LeetCode】144. Binary Tree Preorder Traversal
- 多线程还是多进程的区别
- Git *** Please tell me who you are.
- 电话号码的写法
- 理解“红黑树”
- XP系统缺少msxml4.dll文件,应该放在哪里?
- openstack报错解决一