poj3558 euler
来源:互联网 发布:安卓录屏软件哪个好 编辑:程序博客网 时间:2024/06/07 01:54
转载自:http://blog.csdn.net/code_or_code/article/details/38493609
题目:求 q/p 二进制小数的循环节,起点和长度。
若满足 2^phi[ n ] = 1 (mod n ) 则 数 t = phi [ n ] 一定有一个使 2^k=1 (mod n )成立的 因子 k
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#include<map>using namespace std;const int maxn = 100000 + 10;#define INF 0x3f3f3f3f#define clr(x,y) memset(x,y,sizeof x )typedef long long ll;#define eps 10e-10const ll Mod = 1000000007;typedef pair<ll, ll> P;ll gcd(ll x,ll y){ return y ? gcd(y,x % y) : x;}ll euler(ll n){ ll ans = n; for(ll i = 2; i * i <= n; i ++) { if(n % i == 0) { ans = ans / i * (i - 1); while(n % i == 0) { n /= i; } } } if(n > 1) ans = ans / n * (n - 1); return ans;}ll pow_mod(ll x,ll n,ll mod_val){ ll ans = 1; ll t = x; while(n) { if(n & 1) ans = ans * t % mod_val; n >>= 1; t = t * t % mod_val; } return ans;}ll factor[maxn];int work(ll n){ int len = 0; for(int i = 2; i * i <= n; i ++) { if(n % i == 0) { factor[len ++] = i; factor[len ++] = n / i; } } sort(factor,factor + len); return len;}int main(){ ll n,m; int T = 1; while( ~ scanf("%lld/%lld",&n,&m)) { ll d = gcd(n,m); n /= d; m /= d; ll ans1 = 0,ans2; ll t = m; while(t% 2 == 0) { t /= 2; ans1 ++; } ll r = t; ans2 = euler(r); int len = work(ans2); for(int i = 0; i < len; i ++) { if(pow_mod(2,factor[i],r) == 1) { ans2 = factor[i]; break; } } printf("Case #%d: %lld,%lld \n",T ++,ans1 + 1,ans2); } return 0;}
转载自:http://blog.csdn.net/code_or_code/article/details/38493609
转载自:http://blog.csdn.net/code_or_code/article/details/38493609
阅读全文
0 0
- poj3558 euler
- Euler
- Project Euler
- project euler
- euler测试
- Euler 1
- Euler 2
- Euler 25
- Project Euler
- Euler 92
- EULER 54
- Euler函数
- Euler公式
- euler函数
- Problem Euler
- Euler算法
- Euler Operators
- Euler Circuit
- linux安装apache
- 编程书籍推荐
- 学习淘淘商城第七十九课(LVS+Nginx负载均衡----下篇)
- Python面向对象——01
- C语言中 float double在内存中的存储
- poj3558 euler
- 聚簇索引的页分裂
- 职业日常/素养/格局视野/学习管理
- 安卓app下载及制作入门教程
- ServletRequestListener | 监听器 | 应用例子
- 设计套路:Mysql主键的选择
- CPU后面字母究竟是啥?
- Android M 新的运行时权限开发者需要知道的一切
- React中Ref的使用