poj 3696 The Luckiest number(欧拉函数)
来源:互联网 发布:知乎目标用户 编辑:程序博客网 时间:2024/05/28 15:12
poj 3696 The Luckiest number
由题有
8*(10^x-1)/9=l*k x,k为正整数
10^x-1=l*9*k/8
令m=l*9/gcd(l,8)有
10^x-1=m*k`(这里可以得出10^x和m是互质的,因为10^x-1不可能有2或5两个约数)
即10^x=1mod(m)
因为10和m互质,则可运用欧拉定理:p^eular(m)=1mod(m)
即10^eular(m)=1mod(m)
于是答案便是求eular(m)的最小满足上式的因子积,通过对eular(m)分解质因数来解决
#include<stdio.h>#include<string.h>#define ll long longll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}ll eular(ll n){ll ans=n;for(ll i=2;i*i<=n;i++)if(n%i==0){ans-=ans/i;while(n%i==0) n/=i;}if(n>1) ans-=ans/n;return ans;}ll mod;ll multi(ll a,ll b){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=a*2%mod;b>>=1;}return ans;}ll power_mod(ll a,ll b){ll ans=1;while(b){if(b&1) ans=multi(ans,a);a=multi(a,a);b>>=1;}return ans;}int main(){int cas=1;ll l;while(scanf("%lld",&l)!=EOF&&l){mod=l/gcd(l,8)*9;if(gcd(10,mod)!=1){printf("Case %d: 0\n",cas++);continue;}ll n=eular(mod),ans=n;for(ll i=2;i*i<n;i++)if(n%i==0){ll cnt=0;while(n%i==0){cnt++;n/=i;}while(cnt){if(power_mod(10,ans/i)%mod==1){ans/=i;cnt--;}else break;}}if(n>1) if(power_mod(10,ans/n)%mod==1) ans/=n;printf("Case %d: %lld\n",cas++,ans);}return 0;}
0 0
- POJ 3696 The Luckiest number(欧拉函数)
- POJ 3696 The Luckiest number(欧拉函数)
- poj 3696 The Luckiest number(欧拉函数)
- POJ 3696 The Luckiest number 欧拉函数 或 BSGS
- POJ 3696 The Luckiest Number 欧拉函数
- POJ 3696 The Luckiest Number 欧拉函数
- POJ3696 The Luckiest number【欧拉函数】
- POJ 3696 : The Luckiest number - 欧拉函数,快速幂[数论好题]
- poj 3696 The Luckiest number(欧拉函数+快速幂取模)
- poj 3696 The Luckiest number 欧拉函数在解a^x=1modm的应用
- POJ3696 The Luckiest number 欧拉函数应用
- poj3696.The Luckiest number (阶 && 欧拉函数 && 欧几里德)
- POJ 3696 The Luckiest number
- POJ 3696 The Luckiest number
- poj 3696 The Luckiest number
- poj 3696 The Luckiest number
- poj-3696 The Luckiest number
- POJ 3696 The Luckiest number
- Make Photo Magic 使用Aviary SDK 进行图片编辑开发,功能非常强大!!!!(Aviary SDK安装说明)
- javafx tableview 绑定字段的两种方法
- Python开发问题 还要凑齐1打问题,陆续ING。。。
- AndroidManifest.xml配置文件详解
- 韩顺平PHP学习视频笔记整理001html简介1
- poj 3696 The Luckiest number(欧拉函数)
- cassandra学习笔记二
- Linux新一代文件系统Ext4剖析
- UVA 11488 - Hyper Prefix Sets(Trie)
- 华为机试题--任务调度问题
- poj 3026
- JavaWeb入门:JDBC连接数据库
- POJ 3687 Labeling Balls
- MSSQL 修改数据库de排序规