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

给定\(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;…
题意: 给一个L,求长度最小的全8数满足该数是L的倍数. 分析: 转化为求方程a^x==1modm. 之后就是各种数学论证了. 代码: //poj 3696 //sep9 #include <iostream> #include <algorithm> using namespace std; typedef long long ll; ll L; ll factor[65536]; ll mul(ll x,ll y,ll p) { ll ret=0; while(y){ if(y…
[题目链接] http://poj.org/problem?id=3696 [算法] 设需要x个8 那么,这个数可以表示为 : 8(10^x - 1) / 9, 由题, 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 -> 10^x(mod (9L/d)) = 1 易证a^x(mod n) = 1的最小正整数解是phi(n)的一个约数 那么,求出欧拉函数…
鸣谢: http://blog.csdn.net/yhrun/article/details/6908470 http://blog.sina.com.cn/s/blog_6a46cc3f0100tvqg.html 题意:链接君已失效 方法:各种数论 解析:老师找了两道数论题.这是第一道,听说比第二道简单多了.然而我并不会,看题解也是好顿理解,这题太值得做了!不做悔一生. 咳,回归正题.这道题就是一个奇妙的数.问你最短须要多少个8组成的数能整除他?所以你有思路么?并没有!有思路你也不会来看我唠叨…
The Luckiest Number 题目大意:给你一个int范围内的正整数n,求这样的最小的x,使得:连续的x个8可以被n整除. 注释:如果无解输出0.poj多组数据,第i组数据前面加上Case i: 即可. 想法:这题还是挺好的.我最开始的想法是一定有超级多的数输出0.然后...我就在哪里找啊找....其实这道题是一道比较好玩儿的数论题.我们思考:连续的8可用什么来表示出来?$\frac{(10^x-1)}{9}\cdot 8$.其实想到这一步这题就做完了.这题的精髓就在于告诉我们连续的连…
Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26926   Accepted: 11174   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains…
Ones Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11461   Accepted: 6488 Description Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many d…
该题没思路,参考了网上各种题解.... 注意到凡是那种11111..... 22222..... 33333.....之类的序列都可用这个式子来表示:k*(10^x-1)/9进而简化:8 * (10^x-1)/9=L * k (k是一个整数)8*(10^x-1)=9L*kd=gcd(9L,8)=gcd(8,L)8*(10^x-1)/d=9L/d*k令p=8/d q=9L/d p*(10^x-1)=q*k因为p,q互质,所以q|(10^x-1),即10^x-1=0(mod q),也就是10^x=1…
以前的做法 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; typedef long long LL; LL ai[],ri[],M; void Exgcd(LL a,LL b,LL& d,LL& x,LL& y) { ) { d = a, x = , y = ;} else { Exgcd(b…
这里面的一个转换的小技巧很重要,把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).这一步如何想到的呢?其实是为了使m与10互质而做的.因为这样必有m*p1=10^x-1.使得同余方程 10^x=1 mod m,相信到了这一步,都知道用欧拉定理了.于是只需求出phi(m),枚举其因子,使得同余方程成立即可 #include <iostream> #include <cstd…