国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

hdu 2815 Mod Tree (擴展BSGS)

2019-11-08 01:40:09
字體:
來源:轉載
供稿:網友

Mod Tree

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6172    Accepted Submission(s): 1544PRoblem 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. InputThe input consists of several test cases.Every cases have only three integers indicating K, P, N. (1<=K, P, N<=10^9) OutputThe minimize 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 AuthorAekdyCoin SourceHDU 1st “Old-Vegetable-Birds Cup” Programming Open Contest Recommendlcy   |   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");	}}


上一篇:線性表-循環隊列的表示

下一篇:Servlet

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西吉县| 象山县| 朝阳市| 务川| 上饶县| 万源市| 呼和浩特市| 宜宾县| 从江县| 五常市| 娱乐| 曲阳县| 漾濞| 如东县| 突泉县| 金阳县| 德清县| 工布江达县| 临武县| 淳安县| 乃东县| 健康| 乌拉特中旗| 庆阳市| 临城县| 安顺市| 临泉县| 宜黄县| 姜堰市| 桃园市| 绥德县| 江永县| 呼玛县| 泽库县| 罗田县| 丰台区| 汽车| 丽江市| 临颍县| 旺苍县| 广饶县|