hdu 2815 Mod Tree (扩展BSGS)
来源:互联网 发布:python 内存 结构 编辑:程序博客网 时间:2024/06/01 20:48
Mod Tree
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6172 Accepted Submission(s): 1544
Problem Description
The picture indicates a tree, every node has 2 children.
The depth of the nodes whose color is blue is 3; the depth of the node whose color is pink is 0.
Now out problem is so easy, give you a tree that every nodes have K children, you are expected to calculate the minimize depth D so that the number of nodes whose depth is D equals to N after mod P.
Input
The input consists of several test cases.
Every cases have only three integers indicating K, P, N. (1<=K, P, N<=10^9)
Every cases have only three integers indicating K, P, N. (1<=K, P, N<=10^9)
Output
The minimize D.
If you can’t find such D, just output “Orz,I can’t find D!”
If you can’t find such D, just output “Orz,I can’t find D!”
Sample Input
3 78992 4534 1314520 655365 1234 67
Sample Output
Orz,I can’t find D!820
Author
AekdyCoin
Source
HDU 1st “Old-Vegetable-Birds Cup” Programming Open Contest
Recommend
lcy | We have carefully selected several similar problems for you: 2814 2809 2447 2810 2811
题解:扩展BSGS
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#define LL long long using namespace std;LL a,p,b;map<LL,LL> mp;LL quickpow(LL num,LL x){LL base=num%p; LL ans=1;while (x) {if (x&1) ans=ans*base%p;x>>=1; base=base*base%p;}return ans;}LL gcd(LL x,LL y){LL r;while (y) {r=x%y;x=y; y=r;}return x;}LL exbsgs(LL a,LL b,LL p){a%=p; b%=p;if (b==1) return 0;LL cnt=0,d=1,tmp=1;while ((tmp=gcd(a,p))!=1) {if (b%tmp) return -1;b/=tmp; p/=tmp; cnt++;d=d*(a/tmp)%p;if (b==d) return cnt;}LL m=ceil(sqrt(p)); LL ans=b; LL sum=1;mp.clear();tmp=quickpow(a,m);mp[ans]=0;for (LL i=1;i<=m;i++) ans=ans*a%p,mp[ans]=i; for (int LL i=1;i<=m+1;i++) { d=d*tmp%p; if (mp[d]) { return i*m-mp[d]+cnt;}}return -1;}int main(){freopen("a.in","r",stdin);while (scanf("%I64d%I64d%I64d",&a,&p,&b)!=EOF) {if (b>=p) {printf("Orz,I can’t find D!\n");continue;}LL t=exbsgs(a,b,p);if (t!=-1) printf("%I64d\n",t);else printf("Orz,I can’t find D!\n");}}
0 0
- hdu 2815 Mod Tree (扩展BSGS)
- 【BSGS求离散对数】HDU Mod Tree 2815
- poj 3243 Clever Y&&hdu 2815 Mod Tree(扩展baby_step)
- hdu 2815 Mod Tree 模方程a^x=b(mod n),n为任意正整数+模板题(扩展Baby Step Giant Step)
- HDU 2815 Mod Tree【扩展Baby Step Giant Step解决离散对数问题】
- HDU 2815 Mod Tree 离散对数 扩展Baby Step Giant Step算法
- hdu 2815 Mod Tree(高次同余方程)
- hdu 3930(BSGS+原根+扩展欧几里得)
- Hdu 2815 Mod Tree + Poj 3243 Clever Y 扩展Baby Step Giant Step 解决离散对数问题
- BSGS及扩展BSGS
- BSGS&扩展BSGS
- hdu 2815Mod Tree (数论题)(baby step giant step 小步大步)
- HDU 2815 Mod Tree 解高次同余方程
- hdu 2815 Mod tree 高次同余方程
- HDU 2815 Mod Tree 解a^x = b(mod n)非互质
- [BZOJ1467]Pku3243 clever Y(扩展BSGS)
- 震惊!做了这题就会了快速幂+扩展欧几里德+bsgs(附扩展bsgs)
- POJ 3243 扩展BSGS
- java 日语全角半角的正则
- java数据结构与算法有人知道吗
- theano scan 实例
- n a^o7 !
- 代码阅读2
- hdu 2815 Mod Tree (扩展BSGS)
- 基于QT的电子相册设计与实现
- 面试常见题之虚函数及底层的实现
- 简单的方式寻址数组中第二大数的方式
- FZU 1752 A^B mod C (快速幂+快乘)
- 深度学习笔记(1)——神经网络(neural network)
- C# combox1控件的应用
- Servlet
- Swift 关于tableView的多选和删除