题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走了n步后,x从0~n-1,y从0~n-1都访问过,但x,y不相同. 所以,x肯定要经过0点,所以我只需要求y点就可以了. i,j为每颗苹果树的位置,设在经过了a步后,i到达了0,j到达了M. 则有 1----------------------(i + b * dx) % n = 0 2------…
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the c…
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the c…
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status][Discuss] Description  一种非对称加密算法的密钥生成过程如下: 1.任选两个不同的质数p,q 2.计算N=pq,r=(p−1)(q−1) 3.选取小于r,且与r互质的整数e 4.计算整数d,使得ed≡1KQ/r 5.二元组(N,e)称为公钥,二元组(N,d)称为私钥 当需要加…
题目链接:https://loj.ac/problem/6392 题目大意:给定五个正整数c1,c2,e1,e2,N,其中e1与e2互质,且满足 c1 = m^e1 mod N c2 = m^e2 mod N 求出正整数m 解题思路:因为e1与e2互质,所以可以找到两个整数x,y,满足e1x+e2y=1 所以m^(e1x+e2y)=m^1=m=c1^x*c2^y; 注意如果x或者y小于0时,需要求c1.c2对N的逆元 因为N的范围很大,小于2的63次方,所以不能直接乘,需要用快速乘. 求逆元的时…
思路: 把k*M%N=1可以写成一个不定方程,(k*M)%N=(N*x+1)%N,那么就是求k*M-N*x=1,k最小,不定方程我们可以直接利用exgcd,中间还搞错了: //小小地讲一下exgcd球不定方程原理 对于ax+by=gcd(a,b); 我们设一下a>b,在简单直接把b=0时,gcd(a,b)=a.此时,x=1,y=0; 接着,a>b>0,我们这里可以摆两个式子:①:ax1+by1=gcd(a,b);继续,②:bx2+(a mod b)y2=gcd( b , a mod b…
E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/problem/E Description Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with…
1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(ll l,ll r,ll &x,ll &y) { if(r==0){x=1;y=0;return l;} else { ll d=exgcd(r,l%r,y,x); y-=l/r*x; return d; } } 3.求a关于m的乘法逆元 ll mod_inverse(ll a,ll m){ l…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates(xi, yi). Van…
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the c…