给定\(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. ROS导航包的介绍

    博客转载自:https://blog.csdn.net/handsome_for_kill/article/details/53130707#t3 ROS导航包的应用 利用ROS Navigation ...

  2. App测试从入门到精通之UI测试

    UI(user interface用户界面)的简称.UI测试也是APP测试中需要考虑的一个层面.用户至上,这个太重要了.一个好的App在界面的UI层设计上应该要满足简洁.美观.大气(这个是自己感觉的哈 ...

  3. Linux 查看是64位还是32位

    [root@VM_7_88_centos ~]# uname -a Linux VM_7_88_centos 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36: ...

  4. Digester学习笔记(一)转载

    本博文系转载,作者原文已经无法找到,感谢原作者的辛苦整理 Digester学习笔记(一) 在windows下开发程序,用M$提供的接口处理.ini文件或管理注册表的键值是非常方便的.在java平台上开 ...

  5. Spring:配置文件

    首先是bean.xml,配置所有的bean,一般也叫applicationContext.xml,应用程序上下文.示例: <?xml version="1.0" encodi ...

  6. hibernate的几个重要的类和接口

    Configuration类 该类的对象会自动加载hibernate.cfg.xml文件,同时也可以定义自己的配置文件 sessionFactory接口 由于SessionFactory是重量级的,也 ...

  7. touchmove和touchend的使用

    touchstart:当手指触摸屏幕时触发:即使已经有一个手指放在了屏幕上也会触发.touchmove:当手指在屏幕上滑动时连续的触发.在这个事件发生期间,调用preventDefault()可阻止滚 ...

  8. 搭建基于MinGW平台的《OpenGL蓝皮书(OpenGL SuperBibe 5th)》示例代码编译环境

    副标题:搭建基于MinGW平台的<OpenGL超级宝典>(OpenGL蓝皮书第5版)GLTools 编译环境.示例代码:Triangle.cpp @ SB5.zip 以下内容以及方法均参考 ...

  9. 20165219 2017-2018-2《Java程序设计》结对编程一 第一周总结

    20165219 2017-2018-2<Java程序设计>结对编程一 第一周总结 结对对象 20165219王彦博 20165232何彦达 需求分析 实现一个程序,要求: 1 支持整数运 ...

  10. 738. Monotone Increasing Digits

    Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...