博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Description has only two Sentences(欧拉定理 +快速幂+分解质因数)
阅读量:6875 次
发布时间:2019-06-26

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

Description has only two Sentences

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 124 Accepted Submission(s): 55
 
Problem Description
a
n = X*a
n-1 + Y and Y mod (X-1) = 0.
Your task is to calculate the smallest positive integer k that a
k mod a
0 = 0.
 
Input
Each line will contain only three integers X, Y, a
0 ( 1 < X < 2
31, 0 <= Y < 2
63, 0 < a
0 < 2
31).
 
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
 
/*题意:如题给出的递推公式,让你求出最小的k满足ak mod a0 ==0; 如果没有的话输出impossible初步思路:an=an-1*X+Y => an=Xn*a0+(1+X1+X2+.....+Xn-1)*Y  (里面有一个等比数列)                      => 然后两边同时膜a0 得到 an mod a0 = ( (Xn -1) * Y ) mod a0 / (X -1) = 0                      => 令 T=Y/(X-1) 得到0 =T (Xn - 1) mod a0 (T是任意整数 )                       => 将 mod a0 移到左边                      => 0 (mod a0) = T (Xn - 1)                           (这里的mod是提出来的)                      => 令p=__gcd(a0,T) 然后得到                      => 0 (mod a0/p) = T/p (Xn - 1) = 0 (mod a0') =T' (Xn - 1)                      => 此时a0' 和T' 互质了 那么得到                       => Xn-1=0 (mod a0') 如果(Xn -1 )mod a0' !=0那么就无解 即:                      => Xn mod a0' ==1  否则就是无解的情况                      然后就没有思路了.......#改进:由上一步能得出来 X^n=1(mod a0')                      => 欧拉定理,X^euler(a0')=1(mod a0');//其中X和a0'必须是互质的,不然没有解                      => 如果是互质的,那么然后就可以从a0'中的质因子枚举,然后快速幂就可以了#感悟:!!!质因子忘记排序了,错了两罚!!!!想吐,一天了,就想了这一个题。。。。*/#include
#define ll long longusing namespace std;ll X,Y,A;ll T;/*******************分解质因子模板*********************/bool comp(ll a,ll b){ return a
v;void find(ll n)//分解质因子{ v.clear(); ll m=(ll)sqrt(n+0.5); for(ll i=1;i
1) res=res/a*(a-1); return res;}/**************************欧拉函数模板*****************************/int main(){ //freopen("in.txt","r",stdin); while(scanf("%lld%lld%lld",&X,&Y,&A)!=EOF){ if(Y==0){ puts("1"); continue; } T=Y/(X-1); ll p=__gcd(T,A);//最大公因子 //化简到最简单 T/=p; A/=p;//a0' //cout<
<<" "<
<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6339183.html

你可能感兴趣的文章
优秀交互设计师成长指南
查看>>
SDN网络系统之MiniNet的安装与使用
查看>>
java的Iterator和listIterator的区别
查看>>
服务器虚拟化的好处
查看>>
AxureRP7.0基础教程系列 部件详解 表格Tabel
查看>>
ORACLE之sql语句优化
查看>>
一台机器同时启动多个tomcat
查看>>
Java中的多线程
查看>>
Zookeeper不适合注册中心的原因
查看>>
内核是什么
查看>>
标签的语义
查看>>
Freemarker入门例子
查看>>
利用busybox工具制作微型linux系统二
查看>>
商业无小事,现实生活不在童话故事里
查看>>
Unsupported major.minor version 51.0解决办法
查看>>
我的友情链接
查看>>
新手如何入门
查看>>
15.2-全栈Java笔记:ActionEvent事件类型可以实现哪些功能?
查看>>
apache-tomcat-6.0.X如何配置管理界面Administration Tool
查看>>
Ibatis实例程序
查看>>