昨天终于把欧拉定理的证明看明白了。。。于是兴冲冲地写了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) 的约数,用快速幂判断就好了。

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #define ll long long
  5. #define R register ll
  6. using namespace std;
  7. inline ll g() {
  8. R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
  9. do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
  10. }
  11. ll a[],n,ans;
  12. inline ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
  13. inline ll phi(ll n) {
  14. R m=n; for(R i=;i*i<=n;++i) if(n%i==) {
  15. m=m/i*(i-);
  16. while(n%i==) n/=i;
  17. } if(n>) m=m/n*(n-); return m;
  18. }
  19. inline ll mul(ll a,ll b) {
  20. a%=n,b%=n; R c=(long double)a*b/n;
  21. R ans=a*b-c*n; if(ans<) ans+=n;
  22. if(ans>=n) ans-=n; return ans;
  23. }
  24. inline ll qpow(ll a,ll p) { R ret=;
  25. for(;p;p>>=,a=mul(a,a)) if(p&) ret=mul(ret,a); return ret;
  26. }
  27. signed main() { R t=;
  28. while(n=g(),n!=) { //cout<<n<<endl;
  29. n=*n/gcd(,n);
  30. printf("Case %d: ",++t);
  31. if(gcd(,n)==) {
  32. R p=phi(n),cnt=; //cout<<"PHI: "<<p<<endl;
  33. for(R i=;i*i<=p;++i) if(p%i==) {
  34. a[++cnt]=i;
  35. if(i*i!=p) a[++cnt]=p/i;
  36. } sort(a+,a+cnt+); R i;
  37. for(i=;i<=cnt;++i) if(qpow(,a[i])==) break;
  38. printf("%lld\n",a[i]);
  39. } else printf("0\n");
  40. }
  41. }

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. OSS阿里云文件上传 demo。

    所需jar包: aliyun-openservices-1.2.3.jar jdom-1.1.jar commons-codec-1.4.jar commons-logging-1.1.1.jar g ...

  2. 错误名称:Uncaught SyntaxError: Unexpected token <

    在AngularJS框架下:   控制台输出: 1.谷歌:Uncaught SyntaxError: Unexpected token < 2.火狐:SyntaxError: expected ...

  3. JS上传图片-通过FileReader获取图片的base64

    下面文章,我想要的是: FileReader这个对象,可以借助FileReader来获取上传图片的base64,就可以在客户端显示该图片了.同时,还可以把该图片的base64发送到服务端,保存起来. ...

  4. poj 1637 Sightseeing tour —— 最大流+欧拉回路

    题目:http://poj.org/problem?id=1637 建图很妙: 先给无向边随便定向,这样会有一些点的入度不等于出度: 如果入度和出度的差值不是偶数,也就是说这个点的总度数是奇数,那么一 ...

  5. HDU1026(延时迷宫:BFS+优先队列)

    Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  6. HDOJ1059(多重部分和问题)

    #include<cstdio> #include<cstring> using namespace std; +; ]; int dp[SIZE]; bool check() ...

  7. Java变量初始化的讲解

    首先需要说明的是Java中的变量分为两种:成员变量和局部变量 其中成员变量又可分为:实例变量(非静态变量)和类变量(静态变量) 局部变量(局部变量的作用时间很短,所以一般是存储在栈中的): 1.形参在 ...

  8. Python模块-chardet模块

    chardet模块用来获取文件的编码 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import chardet f = o ...

  9. IOS的设计模式

    对象创建 原型(Prototype) 使用原型实例指定创建对象的种类,并通过复制这个原型创建新的对象. NSArray *array = [[NSArray alloc] initWithObject ...

  10. web安全之同源策略

    为什么使用同源策略?一个重要原因就是对cookie的保护,cookie 中存着sessionID .如果已经登录网站,同时又去了任意其他网站,该网站有恶意JS代码.如果没有同源策略,那么这个网站就能通 ...