HDU 5393 【数论】
来源:互联网 发布:北京军工软件开发 编辑:程序博客网 时间:2024/06/07 09:23
最近总被虐…被虐…虐…
%%%fsf大爷,太强辣
欢迎神犇打脸(求轻喷
题目大意:给出
…首先 k = 0,1 要特判 …
n 次操作后的值就是
所以就能得到
两边可以约去
现在就是求
这里
但是右边不是质数,所以要分解质因数然后 CRT 合并(其实这步是多余的。。。我又智障了嘛。。。TAT
对于
设最小的 n 为 x,那么有
所以对于 n ,若满足上述表达式且
然而
为什么感觉不太科学…
#include<iostream>#include<algorithm>#include<cstdlib>#include<cstdio>#include<string>#include<cstring>#include<ctime>#include<cmath>#define INF 2000000020#define LL long longusing namespace std;LL T,k,b,x,p,tot,ans;struct node{int p,k;}A[100];LL gcd(LL a,LL b){ return b ? gcd(b,a % b) : a;}LL lcm(LL a,LL b){ return a / gcd(a,b) * b;}LL ksm(LL a,LL b,LL p){ LL ret = 1; for (;b;b >>= 1,a = a * a % p) if (b & 1) ret = ret * a % p; return ret;}void divid(int x){ for (int i = 2;i * i <= x;i ++) if (x % i == 0) { A[++ tot] = (node){i,1},x /= i; for (;x % i == 0;x /= i,A[tot].k ++); } if (x ^ 1) A[++ tot] = (node){x,1};}bool cmp(const node &a,const node &b){ return a.p < b.p;}LL cal(int tt){ LL P = 1,phi,p = A[tt].p; for (int i = 1;i <= A[tt].k;i ++) P *= p; phi = P / p * (p - 1); while (phi % p == 0 && ksm(k,phi / p,P) == 1) phi /= p; p --; for (int i = 2;i * i <= p;i ++) { for (;phi % i == 0 && ksm(k,phi / i,P) == 1;phi /= i); for (;phi % (p/i) == 0 && ksm(k,phi / (p/i),P) == 1;phi /= (p/i)); } if (phi % p == 0 && ksm(k,phi / p,P) == 1) phi /= p; return phi;}int main(){ cin >> T; while (T --) { cin >> k >> b >> x >> p; if (!k) {printf("%d\n",b == x ? 1 : -1);continue;} if (k == 1) {printf("%d\n",b ? p / gcd(p,b): 1);continue;} p /= gcd((k - 1) * x + b,p); if (p == 1) {puts("1");continue;} if (gcd(p,k) ^ 1) {puts("-1");continue;} tot = 0,divid(p),divid(k - 1); sort(A + 1,A + tot + 1,cmp); for (int i = 2;i <= tot;i ++) if (A[i].p == A[i - 1].p) A[i].k += A[i - 1].k,A[i - 1].p = INF; sort(A + 1,A + tot + 1,cmp); for (;A[tot].p == INF;tot --); ans = 1; for (int i = 1;i <= tot;i ++) ans = lcm(ans,cal(i)); cout << ans << endl; } return 0;}
0 0
- HDU 5393 【数论】
- HDU 2204 (数论)
- 数论 MillerRabin hdu 3792
- HDU 3123 数论
- 【数论】HDU-4196-Remoteland
- HDU 3988 数论
- HDU 1787 数论
- hdu 1395 数论
- HDU 2104数论 欧几里得
- HDU 1060 数论
- HDU 2161 Primes 数论
- HDU 1695 GCD 数论
- HDU 1568 Fibonacci 数论
- hdu 4542 数论
- hdu 1722(数论)
- hdu 1492(数论)
- hdu 2554 (数论)
- hdu 2964 (数论)
- 快速搭建SpringMVC + restful 框架
- A003-算法-随机数
- 【转载】eclipse 安装svn插件
- Xshell5下利用sftp上传下载传输文件
- Python 布尔值
- HDU 5393 【数论】
- 第一章 Introduction exercise 13-20
- dash mpd之片段名(SegmentList SegmentURL)
- python 获取alert信息并截取alert图片
- [Nutch]问题解决:Exception in thread "main" java.io.IOException: Failed to set permissions of path
- Linux 防火墙之iptables
- GRASP (职责分配原则)【转】
- Django一:nginx+uwsgi+django+python+mac
- python与系统的交互