数学实在是差到不行了……

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
#define LL __int64
const LL maxn=1001;
LL e[maxn],t;
LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
LL euler_phi(LL n)//求单个欧拉函数
{
LL m=(LL)sqrt(n+0.5);
LL i,ans=n;
for(i=2;i<=m;i++)
if(n%i==0)
{
ans=ans/i*(i-1);
while(n%i==0)n/=i;
}
if(n>1)ans=ans/n*(n-1);
return ans;
}
void find(LL n)//找出所有因子
{
LL m=(LL)sqrt(n+0.5);
for(LL i=1;i<m;i++)
if(n%i==0){e[t++]=i;e[t++]=n/i;}
if(m*m==n)e[t++]=m;
}
LL pow_mod(LL a,LL b,LL mod)//快速幂
{
LL s=1;
while(b)
{
if(b&1)
s=(s*a)%mod;
a=(a*a)%mod;
b=b>>1;
}
return s;
}
int main()
{
LL a,x,y;
while(cin>>x>>y>>a)
{
LL m,phi,i;
if(y==0){cout<<"1"<<endl;continue;}
m=a/gcd(y/(x-1),a);
if(gcd(m,x)!=1){cout<<"Impossible!"<<endl;continue;}//不互质,则x^k%m必定是gcd(m,x)的倍数
phi=euler_phi(m);
t=0;
find(phi);
sort(e,e+t);
for(i=0;i<t;i++)
{
if(pow_mod(x,e[i],m)==1)
{
cout<<e[i]<<endl;
break;
}
}
}
return 0;
}
/*
euler_phi(i),欧拉函数,表示求不大于i且与i互质的正整数个数。 本题递推公式化简下可得到通项公式:ak=a0+Y/(X-1)*(X^k-1);后半部分是等比数列的和。
现在求ak%a0=0,即Y/(X-1)*(X^k-1)%a0==0,令m=a0/gcd(Y/(X-1),a0),则可推到求最小的k使得
(X^k-1)%m==0,即X^k==1(mod m).
根据欧拉定理得X^euler_phi(m)==1(mod m).(X与m互质)
又由抽屉原理可知,X^k的余数必定是根据euler_phi(m)的某个因子为循环节循环的。
所以求出最小的因子k使得X^k%m==1,即为答案
*/

HDU 3307 Description has only two Sentences的更多相关文章

  1. hdu 3307 Description has only two Sentences (欧拉函数+快速幂)

    Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  2. Description has only two Sentences(欧拉定理 +快速幂+分解质因数)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...

  3. hdu 3307(欧拉函数+好题)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  4. Description has only two Sentences(hdu3307)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  5. hdu 3307 简单的指数循环节

    #include<stdio.h>#include<string.h>#include<algorithm>#define LL __int64using name ...

  6. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  7. [SinGuLaRiTy] 数论题目复习

    [SinGuLaRiTy-1020] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [CQBZOJ 1464] Hankson 题目描述 H ...

  8. hdu3307 欧拉函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3307 Description has only two Sentences Time Limit: 3 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. localhost简介、localhost与 127.0.0.1 及 本机IP 的区别

    localhost是什么意思? 相信有人会说是本地ip,曾有人说,用127.0.0.1比localhost好,可以减少一次解析. 看来这个入门问题还有人不清楚,其实这两者是有区别的. localhos ...

  2. VS2013 快捷键 与 RESHARPER 冲突

    1.VS设置工具-->选项-->环境-->键盘-->重置 2.RESHARPER -->Options-->Environment → Keyboard & ...

  3. svn和ftp的区别

    svn和ftp的区别是: ftp修该文件后就会替换原来的内容无法恢复.如果要回复,还需要自己在替换前做备份.如果遇到多人同时操作同一文件就会很头疼.且无法对相应修改进行记录. svn可以将你每一次的修 ...

  4. K-Modes算法[聚类算法]

    聚类算法k-Modes的实现 <?php /* *Kmodes算法(聚类算法的实现) */ /* *获取簇的数目 */ //----------------------------------- ...

  5. 用SCMD2.0.8.0汉化版制作OB地图简易教程

    [综合] [复制链接]     Fenix_king       153 主题 0 好友 1万 积分 金星 该用户从未签到 星币 6392 水晶 0 星望 22 精华 0 发消息 电梯直达 楼主   ...

  6. jQuery 插件入门

    先看http://www.cnblogs.com/lideng/p/3605551.html http://www.cnblogs.com/xcj26/p/3345556.html (非常细致  很多 ...

  7. VS插件

    VS插件 背景 前些天去考科目二,感觉经历了一场不是高考却胜似高考的考试(10年前的5分之差, 还是难以释怀)!    一行八人,就我学的时间最少(4天,8人一辆车),教练都觉得我肯定还得再来一次! ...

  8. BZOJ 2253: [2010 Beijing wc]纸箱堆叠

    题目 2253: [2010 Beijing wc]纸箱堆叠 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 239  Solved: 94 Descr ...

  9. aliyun opts 集锦

    <一,>,aliyun 使用数据盘(aliyun新增数据盘使用,创建vg,aliyun 镜像系统本身未使用lvm-vg-lv) 1.1直接挂载文件系统 较易,不做分析 http://hel ...

  10. 如何解决Android 5.0中出现的警告:Service Intent must be explicit

    有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent  must be explitict,也就是说从Lollip ...