昨天终于把欧拉定理的证明看明白了。。。于是兴冲冲地写了2道题,发现自己啥都不会qwq


题意:给定一个正整数L<=2E+9,求至少多少个8连在一起组成正整数是L的倍数。

这很有意思么。。。

首先,连续的8可表示为:8*(10^x-1)/9;

那么就是L|8*(10^x-1)/9 => 9*L|8*(10^x-1) ,求最小的x;

我们设d=gcd(L,8)

则9*L/d | 8/d*(10^x-1),因为此时9*L/d 和 8/d 互质,所以9*L/d | 10^x-1,所以 10^x ≡ 1 (mod 9*L/d);

然后要证明一个结论:a^x ≡ 1 (mod n)的最小正整数解x0能整除φ(n)

证明:

反证:设不能整除,则设φ(n)=q*x0+r;(1<=r<x0)

因为a^x0 ≡ 1 (mod n),所以a^(q*x0) ≡ 1(mod n)

又因为a^φ(n) ≡ 1 (mod n),所以a^r ≡ 1 (mod n)

因为r<x0,所以假设不成立;

证毕。

所以我们枚举每个φ(9*L/d) 的约数,用快速幂判断就好了。

#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
#define R register ll
using namespace std;
inline ll g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
ll a[],n,ans;
inline ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
inline ll phi(ll n) {
R m=n; for(R i=;i*i<=n;++i) if(n%i==) {
m=m/i*(i-);
while(n%i==) n/=i;
} if(n>) m=m/n*(n-); return m;
}
inline ll mul(ll a,ll b) {
a%=n,b%=n; R c=(long double)a*b/n;
R ans=a*b-c*n; if(ans<) ans+=n;
if(ans>=n) ans-=n; return ans;
}
inline ll qpow(ll a,ll p) { R ret=;
for(;p;p>>=,a=mul(a,a)) if(p&) ret=mul(ret,a); return ret;
}
signed main() { R t=;
while(n=g(),n!=) { //cout<<n<<endl;
n=*n/gcd(,n);
printf("Case %d: ",++t);
if(gcd(,n)==) {
R p=phi(n),cnt=; //cout<<"PHI: "<<p<<endl;
for(R i=;i*i<=p;++i) if(p%i==) {
a[++cnt]=i;
if(i*i!=p) a[++cnt]=p/i;
} sort(a+,a+cnt+); R i;
for(i=;i<=cnt;++i) if(qpow(,a[i])==) break;
printf("%lld\n",a[i]);
} else printf("0\n");
}
}

2019.05.11

POJ3696 The Luckiest Number 欧拉定理的更多相关文章

  1. POJ3696 The Luckiest number

    题意 Language:Default The Luckiest number Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7 ...

  2. POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)

    Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...

  3. [POJ3696]The Luckiest number(数论)

    题目:http://poj.org/problem?id=3696 题意:给你一个数字L,你要求出一个数N,使得N是L的倍数,且N的每位数都必须是8,输出N的位数(如果不存在输出0) 分析: 首先我们 ...

  4. POJ_3696 The Luckiest number 【欧拉定理+同余式+对取模的理解】

    一.题目 Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his ...

  5. poj 3696 The Luckiest Number

    The Luckiest Number 题目大意:给你一个int范围内的正整数n,求这样的最小的x,使得:连续的x个8可以被n整除. 注释:如果无解输出0.poj多组数据,第i组数据前面加上Case ...

  6. poj_3696_The Luckiest number

    Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own ...

  7. HDU 2462 The Luckiest number

    The Luckiest number Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Ori ...

  8. The Luckiest number(hdu2462)

    The Luckiest number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. 「POJ3696」The Luckiest number【数论,欧拉函数】

    # 题解 一道数论欧拉函数和欧拉定理的入门好题. 虽然我提交的时候POJ炸掉了,但是在hdu里面A掉了,应该是一样的吧. 首先我们需要求的这个数一定可以表示成\(\frac{(10^x-1)}{9}\ ...

随机推荐

  1. Oracle 12C 新特性之级联truncate

    12c之前的版本中,在子表引用一个主表以及子表存在记录的情况下,是不提供截断此主表操作的.而在 12c 中的带有 CASCADE 操作的TRUNCATE TABLE 可以截断主表中的记录,并自动对子表 ...

  2. 11g RAC OCR,VOTING DISK存储全部损坏,利用自动备份,恢复OCR,VOTING DISK到新存储。

    背景: 11g R2 rac 的orc ,voting disk asm存储磁盘全部损坏.通过调查得知 损坏的 OCR磁盘对应为 VOL1 ,voting disk磁盘对应于 VOL2 . 故,添加a ...

  3. [转]HTTP头的Expires与Cache-control

    1.概念 Cache-control用于控制HTTP缓存(在HTTP/1.0中可能部分没实现,仅仅实现了Pragma: no-cache) 数据包中的格式: Cache-Control: cache- ...

  4. Poj1207 The 3n + 1 problem(水题(数据)+陷阱)

    一.Description Problems in Computer Science are often classified as belonging to a certain class of p ...

  5. HDU5438:Ponds(拓扑排序)

    Ponds Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Sub ...

  6. 彻底删除kafka下面的topic

    如果只是用kafka-topics.sh的delete命令删除topic,会有两种情况: 如果当前topic没有使用过即没有传输过信息:可以彻底删除 如果当前topic有使用过即有过传输过信息:并没有 ...

  7. Ruby中print、p、puts的区别

    三个方法的作用都是将一个字符串打印到控制台  比较项目  puts  print p   换行符 末尾添加换行符  末尾不加换行符  末尾添加换行符  非字符串对象的输出  调用该对象的to_s方法 ...

  8. 关于KMeans的评价及聚簇结果的得到

    import numpy as npfrom sklearn.cluster import KMeansfrom sklearn import metricsimport matplotlib.pyp ...

  9. JS中数组方法小总结

    1.array.concat(item……) 返回:一个新数组 该方法产生一个新数组,它包含一份array的浅复制,并把一个或多个参数item附加在其后.如果参数item是一个数组,那么它的每个元素会 ...

  10. Struts2 配置项

    基础Constants struts.devMode  可选值true,false (默认false),在开发模式下,struts2的动态重新加载配置和资源文件的功能会默认生效.同时开发模式下也会提供 ...