还是挺难的吧......勉强看懂调了半天

首先表达式可以写成 8(10^x -1)/9,题意为求一个最小的x使L | 8(10^x -1)/9

设d=gcd(L,8)

L | 8(10^x -1)/9

<=>9L | 8(10^x -1)

<=>9L/d | 10^x -1 (因为 9L/d 和 8/d 互质了 所以 9L/d 能整除(8/d)*(10^x-1)和 8/d 无关,所以可以去掉)

<=>10^x 同余 1(mod 9L/d)

引理:

若a,n互质,则满足10^x同余1(mod n)的最小正整数x0是phi(n)的约数

反证法:

假设满足a^x 同余 1(mod n)的最小正整数x0不能整除phi(n)

设phi(n)=q*x0+r(0<r<x0),因为a^x0 同余1(mod n),所以a^(q*x0)同余1(mod n)

根据欧拉定理a^phi(n)同余1(mod n),所以a^r同余1(mod n),与x0最小矛盾

无解的时候就是q与10不互质的时候,因为若q与10有公因子d:
1.若d=2,q=2*k,那么10^x=2^x*5^x=1%2k
   即2^x*5^x=1+2k*m,左边为偶数,右边为奇数,显然矛盾。
2.若d=5,q=5*k,那么10^x=2^x*5^x=1%5k
   即2^x*5^x=1+5k*m,左边是5的倍数,右边不是5的倍数,显然矛盾。

注意:乘的时候会爆longlong,手写乘法,要用根号的试除法求约数,不然会T

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll n,cnt;
ll x[];
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
ll eular(ll n){
ll ans=n;
for(ll i=;i*i<=n;i++){
if(n%i==){
ans=ans/i*(i-);
while(n%i==)n/=i;
}
}
if(n>)ans=ans/n*(n-);
return ans;
}
ll mul(ll a,ll b,ll mod){
ll ans=;
while(b){
if(b&)ans=(ans+a)%mod;
a=(a<<)%mod;
b>>=;
}
return ans;
}
ll qpow(ll a,ll b,ll mod){
ll base=a,ans=;
while(b){
if(b&)ans=mul(ans,base,mod);
base=mul(base,base,mod);
b>>=;
}
return ans%mod;
} int main(){
int t=;
while(){
int fl=;cnt=;
scanf("%lld",&n);
if(n==)break;
ll d=*n/gcd(n,);
if(gcd(,d)!=){
printf("Case %d: 0\n",++t);
}
else{
ll phi=eular(d);
for(ll i=;i*i<=phi;i++){
if(phi%i==){
x[++cnt]=i;
if(i*i!=phi)x[++cnt]=phi/i;
}
} sort(x+,x+cnt+);
for(int i=;i<=cnt;i++)
if(qpow(,x[i],d)==){
printf("Case %d: %lld\n",++t,x[i]);
break;
}
}
}
}

[题解](同余)POJ_3696_The Luckiest Number的更多相关文章

  1. poj_3696_The Luckiest number

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

  2. poj 3696 The Luckiest Number

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

  3. POJ3696 The Luckiest number

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

  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. POJ3696:The Luckiest number(欧拉函数||求某数最小的满足题意的因子)

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

  6. HDU 2462 The Luckiest number

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

  7. The Luckiest number(hdu2462)

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

  8. LeetCode Continuous Subarray Sum 题解 同余前缀和 Hash表

    文章目录 题意 思路 特殊情况k=0 Source Code 1 Source Code 2 题意 给定一个数组和一个整数k,返回是否存在一个长度至少为2的连续子数组的和为k的倍数. 思路 和上一篇博 ...

  9. POJ 3696 The Luckiest number (欧拉函数,好题)

    该题没思路,参考了网上各种题解.... 注意到凡是那种11111..... 22222..... 33333.....之类的序列都可用这个式子来表示:k*(10^x-1)/9进而简化:8 * (10^ ...

随机推荐

  1. jQuery选项卡tabulous

    jQuery选项卡tabulous,jQuery,选项卡,tab标签切换代码,扁平设计,jQuery选项卡tabulous是一款支持Scale.Slide.Scale Up.Flip等效果jquery ...

  2. PHP的Calling Scope(::调用非静态方法)

    今天在群里发现有人说,PHP可以用::调用非静态方法,一致没这么试过,发现了鸟哥的blog写了这个问题的具体解释,就搬过来: 这个问题乍看, 确实很容易让人迷惑, 但实际上, 造成这样的误解的根本原因 ...

  3. tflearn 在每一个epoch完毕保存模型

    关键代码:tflearn.DNN(net, checkpoint_path='model_resnet_cifar10', max_checkpoints=10, tensorboard_verbos ...

  4. Go丨语言对数据库操作报错 panic: dial tcp 127.0.0.1:3306: connectex: No connection could be made because the target machine actively refused it.

    panic: dial tcp 127.0.0.1:3306: connectex: No connection could be made because the target machine ac ...

  5. listen and translation exercise 53

    It was hard work and there weren't any interesting things for him. You should be an expert with comp ...

  6. animation-delay负值

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. BZOJ3784:树上的路径

    浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...

  8. Java关键字以及一些基础解释

    Java Se:Java Me 和Java Ee的基础,允许开发和部署在桌面,服务器,嵌入式环境和实时环境中使用的java程序,支持java web服务开发类 java ee:是目前java技术应用最 ...

  9. C# 把datagridview控件上的表格输出到excel文件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. MATLAB 内存容量修改 zz

    MATLAB 内存容量修改 - Oliver的日志 - 网易博客 在用MATLAB做图像处理时 经常会碰到内存溢出的情况,可用如下方法修改,使得MATLAB的内存容量最大: 出自matlab:matl ...