博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 3307 Description has only two Sentences (欧拉函数+快速幂)
阅读量:7021 次
发布时间:2019-06-28

本文共 2029 字,大约阅读时间需要 6 分钟。

Description has only two Sentences

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 852 Accepted Submission(s): 259
Problem Description
an = X*an-1 + Y and Y mod (X-1) = 0.
Your task is to calculate the smallest positive integer k that ak mod a0 = 0.
Input
Each line will contain only three integers X, Y, a0 ( 1 < X < 231, 0 <= Y < 263, 0 < a0 < 231).
Output
For each case, output the answer in one line, if there is no such k, output "Impossible!".
Sample Input
2 0 9
Sample Output
1
Author
WhereIsHeroFrom
Source
HDOJ Monthly Contest – 2010.02.06
Recommend
wxl | We have carefully selected several similar problems for you: 3308 3309 3306 3310 3314

 

 

因为考试放下了挺久,后来发现不做题好空虚寂寞...于是决定在做一段时间再说。

 

1 //31MS    236K    1482 B    G++ 2 /* 3  4     又是不太懂的数学题,求ak,令ak%a0==0 5       6     欧拉函数+快速幂: 7          欧拉函数相信都知道了。 8          首先这题推出来的公式为: 9              ak=a0+y/(x-1)*(x^k-1);10          11          明显a0是可以忽略的,其实就是要令 12              y/(x-1)*(x^k-1) % a0 == 0;13          可令 m=a0/(gcd(y/(x-1),a0)),然后就求k使得14              (x^k-1)%m==0 即可15              即 x^k==1(mod m)16          17          又欧拉定理有:18               x^euler(m)==1(mod m)  (x与m互质,不互质即无解)19          20          由抽屉原理可知 x^k 的余数必在 euler(m) 的某个循环节循环。21          故求出最小的因子k使得 x^k%m==1,即为答案 22 23 */24 #include
25 #include
26 #include
27 __int64 e[1005],id;28 int cmp(const void*a,const void*b)29 {30 return *(int*)a-*(int*)b;31 }32 __int64 euler(__int64 n)33 {34 __int64 m=(__int64)sqrt(n+0.5);35 __int64 ret=1;36 for(__int64 i=2;i<=m;i++){37 if(n%i==0){38 ret*=i-1;n/=i; 39 }40 while(n%i==0){41 ret*=i;n/=i;42 }43 }44 if(n>1) ret*=n-1;45 return ret;46 }47 __int64 Gcd(__int64 a,__int64 b)48 {49 return b==0?a:Gcd(b,a%b);50 }51 void find(__int64 n)52 {53 __int64 m=(__int64)sqrt(n+0.5);54 id=0;55 for(__int64 i=1;i

 

转载于:https://www.cnblogs.com/GO-NO-1/p/3807563.html

你可能感兴趣的文章
SQL Server 调优系列进阶篇 - 如何维护数据库索引
查看>>
需要总结的知道
查看>>
「视频直播技术详解」系列之四:推流和传输
查看>>
微信小程序之快速接入七牛云
查看>>
cursor.MySQLCursorDict Class
查看>>
一行代码实现java list去重
查看>>
《zw版·Halcon-delphi系列原创教程》 Halcon分类函数008,matrix,矩阵函数
查看>>
[Codeforces Round #351 Div. 2] 673A Bear and Game
查看>>
php base64图片保存
查看>>
轻松掌握Ajax.net系列教程四:用Ajax.net实现客户端回调(Callback)
查看>>
Kinect+OpenNI学习笔记之3(获取kinect的数据并在Qt中显示的类的设计)
查看>>
整理 读过感觉不错的深度学习博客(更新中)
查看>>
响应在此上下文中不可用
查看>>
4、HTTP(下)
查看>>
redis持久化
查看>>
2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1009
查看>>
poj3368(RMQ——ST)
查看>>
PHP解说日全食红月
查看>>
mybatis根据property获取column
查看>>
Windows Docker 安装
查看>>