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

首先表达式可以写成 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. Spring Boot2.0之多环境配置

    本地开发环境 测试环境 实际项目中 区分不同的环境配置文件信息 首先创建三种不同场景下的配置文件: 内容分别是: ###dev http_url="dev" ###prdhttp_ ...

  2. 算法(Algorithms)第4版 练习 1.3.13

    (a) 0 1 2 3 4 5 6 7 8 9 (b) 4 6 8 7 5 3 2 9 0 1 (c) 2 5 6 7 4 8 9 3 1 0 (d) 4 3 2 1 0 5 6 7 8 9 答案:b ...

  3. 一篇文章教你如何用R进行数据挖掘

    一篇文章教你如何用R进行数据挖掘 引言 R是一种广泛用于数据分析和统计计算的强大语言,于上世纪90年代开始发展起来.得益于全世界众多 爱好者的无尽努力,大家继而开发出了一种基于R但优于R基本文本编辑器 ...

  4. ES6 Map数据结构

    Map JavaScript 的对象(Object),本质上是键值对的集合(Hash 结构),但是传统上只能用字符串当作键.这给它的使用带来了很大的限制. ES6 提供了 Map 数据结构.它类似于对 ...

  5. RQNOJ 188 购物问题:树形dp

    题目链接:https://www.rqnoj.cn/problem/188 题意: 商场以超低价格出售n个商品,购买第i个商品所节省的金额为w[i]. 为了防止亏本,有m对商品是不能同时买的.但保证商 ...

  6. memcached高可用

    http://sourceforge.net/projects/repcached/ memcached-1.2.8-repcached-2.2.tar.gz tar zxvf memcached-1 ...

  7. spring的了解以及简单框架的搭建

    了解spring: Spring是一个开源的控制反转(Inversion of Controller)和面向切面(AOP)的框架,目的是为了简化开发. IOC(控制反转): public class ...

  8. codeforces 651E E. Table Compression(贪心+并查集)

    题目链接: E. Table Compression time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  9. LED接口

    通常我们都听到别人说DVI接口.VGA接口等,可是这些接口是什么意思,led显示屏厂家小编为您解析其含义与不同之处.   1.DVI接口 DVI接口相校于VGA.HDMI.DP等接口来说体积较大,是目 ...

  10. Oracle数据库获取一行记录中某几个字段的最大值/最小值函数

    在数据库的开发过程中,我们可能会遇到这样的需求,获取一行记录中某几个字段的最大值或者是最小值,oracle给我们提供了解决这种需求的函数,如下所示:   greatest(col1, col2, co ...