给定\(L\),求最小的\(x\)满足$ L|8\frac{10^x-1}{9} $

/*H E A D*/
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll euler(ll n){
ll ans=n;
for(ll i = 2; i*i <= n; i++){
if(n%i==0){
ans=ans/i*(i-1);
while(n%i==0) n/=i;
}
}
if(n>1) ans=ans/n*(n-1);
return ans;
}
ll fmp(ll a,ll b,ll m){
ll ans=0;
while(b){
if(b&1) ans=(ans+a)%m;
a=(a+a)%m;
b>>=1;
}
return ans;
}
ll fpw(ll a,ll n,ll m){
ll ans=1;
while(n){
if(n&1) ans=fmp(ans,a,m);
a=fmp(a,a,m);
n>>=1;
}
return ans;
}
int main(){
ll L,kase=0;
while(cin>>L){
if(L==0) break;
L=9ll*L/gcd(L,8);
printf("Case %lld: ",++kase);
if(gcd(10,L)!=1){
println(0);
continue;
}
ll p=euler(L);
ll ans=p;
for(ll i=1; i*i<=p; i++){
if(p%i!=0)continue;
if(fpw(10,i,L)==1){
ans=min(ans,i);
}
if(i*i!=p&&fpw(10,p/i,L)==1){
ans=min(ans,p/i);
}
}
println(ans);
}
return 0;
}

POJ - 3696 同余的更多相关文章

  1. poj 3696 The Luckiest number 欧拉函数在解a^x=1modm的应用

    题意: 给一个L,求长度最小的全8数满足该数是L的倍数. 分析: 转化为求方程a^x==1modm. 之后就是各种数学论证了. 代码: //poj 3696 //sep9 #include <i ...

  2. 【POJ 3696】 The Luckiest number

    [题目链接] http://poj.org/problem?id=3696 [算法] 设需要x个8 那么,这个数可以表示为 : 8(10^x - 1) / 9, 由题, L | 8(10^x - 1) ...

  3. POJ 3696 神TM数论

    鸣谢: http://blog.csdn.net/yhrun/article/details/6908470 http://blog.sina.com.cn/s/blog_6a46cc3f0100tv ...

  4. poj 3696 The Luckiest Number

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

  5. poj 1426(同余搜索)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26926   Accepted: 111 ...

  6. poj 2251(同余)

    Ones Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11461   Accepted: 6488 Description ...

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

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

  8. POJ 1006 同余方程组

    以前的做法 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring& ...

  9. POJ 3696

    这里面的一个转换的小技巧很重要,把888...8转换成(10^x-1)/9*8.神来之笔,佩服. 这样有(10^x-1)/9*8=L*p得10^x-1=L*p*9/8,设m=9*L/gcd(L,8). ...

随机推荐

  1. 面试题:Java程序员最常用的20%技术 已看1

    首先常用api(String,StringBuffer/StringBuilder等) 1.集合类,线程类 2.Servlet(很少用纯粹的servlet写,但你要懂,因为很多框架都是基于servle ...

  2. Hyperledger Fabric Chaincode解析

    首先看下Blockchain结构,除了header指向下一个block的hash value外,block是由一组transaction构成, Transactions --> Blocks - ...

  3. CentOS 安装mongodb3.0 二进制包

    1.下载mongodb因为64位系统CentOS,所以下载64位的安装包: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0 ...

  4. django: django rest framework 分页

    django: django rest framework 分页 2018年06月22日 13:41:43 linux_player_c 阅读数:665更多 所属专栏: django 实战   版权声 ...

  5. CentOS7下源码包方式安装Erlang

    1.官网上下载源码包:OTP 19.1 Source File 2.把源码放在source目录中 , 解压 :tar -zxvf otp_src_19.1.tar.gz [或者 直接下载 rpm包 e ...

  6. css3的那些高级选择器一

    css大家都不陌生了,从1996年12月css1正式推出,经历了1998年5月css2,再到2004年2月css2.1,最后一直到2010年推出的css3.css的推出给web带来巨大 的改变,使我们 ...

  7. HTML、CSS、JavaScript网页制作从入门到精通 (刘西杰) pdf扫描版彩色版​

    html.css.JavaScript网页制作从入门到精通中从基础知识开始讲起,如html的基本标记.文字与段落标记.表格标记.超链接标记……同时介绍了目前流行的web标准与css网页布局实例,以及基 ...

  8. C# winform 打开新窗体 关闭当前窗体

    Form1 的Button 下 { Form2 f2 = new Form2(); f2.ShowDialog(this);// this.Close(); } Form2 的load 下 { //只 ...

  9. C#英文面试常见问题[转]

    I was reading a post about some common C# interview questions, and thought I'd share some of mine. T ...

  10. angular ng-content

    <p> child works! </p> <ng-content></ng-content> <app-child> 父组件投影 < ...