题目链接: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-----------------------(j + b * dy) % n = M % n

则2 * dx - 1 * dy消掉未知数 b.

得方程。          

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
const int maxn = 1e6+;
int vis[maxn];
ll n,m,dx,dy;
ll ex_gcd(ll a,ll b, ll &x, ll &y)
{
if (b == )
{
x = ;
y = ;
return a;
}
else
{
ll gcd = ex_gcd(b, a % b, x, y);
ll t = x;
x = y;
y = t - (a / b) * y;
return gcd;
}
}
int main()
{
cin>>n>>m>>dx>>dy;
ll x,y;
ex_gcd(dx,n,x,y);
while(x<) x+=n;
ll inv = x;
ll ans = ;
ll i,j;
ll mm;
for(int k=;k<m;k++)
{
scanf("%I64d %I64d",&i,&j);
mm = ((dx*j-dy*i)%n+n)%n*inv%n;
vis[mm]++;
}
ll mmm = ;
for(int k=;k<n;k++)
{
if(vis[k]>ans)
{
ans = vis[k];
mmm = k;
}
}
printf("0 %I64d\n",mmm);
return ;
}

codeforces 492E. Vanya and Field(exgcd求逆元)的更多相关文章

  1. CodeForces 492E Vanya and Field (思维题)

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces 492E Vanya and Field

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)

    4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status ...

  4. #6392. 「THUPC2018」密码学第三次小作业 / Rsa (exgcd求逆元+快速幂+快速乘)

    题目链接:https://loj.ac/problem/6392 题目大意:给定五个正整数c1,c2,e1,e2,N,其中e1与e2互质,且满足 c1 = m^e1 mod N c2 = m^e2 m ...

  5. 51nod1256【exgcd求逆元】

    思路: 把k*M%N=1可以写成一个不定方程,(k*M)%N=(N*x+1)%N,那么就是求k*M-N*x=1,k最小,不定方程我们可以直接利用exgcd,中间还搞错了: //小小地讲一下exgcd球 ...

  6. Codeforces Round #280 (Div. 2) E. Vanya and Field 数学

    E. Vanya and Field Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/492/pr ...

  7. 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数

    1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(l ...

  8. Codeforces Round #280 (Div. 2)E Vanya and Field(简单题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 本场题目都比较简单,故只写了E题. E. Vanya and Field Vany ...

  9. Codeforces Round #280 (Div. 2) E. Vanya and Field 思维题

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 打印出最后执行的mysql 语句

    db.php 文件中添加 public function getlastsql(){ return $this->sql; } 入口文件中添加,公共方法 function getlastsql( ...

  2. Java-if 嵌套结构

    import java.util.Scanner; public class ifs{ public static void main(String args[]){ Scanner in=new S ...

  3. 配置php时。提示的错误session_start(): Failed to initialize storage module解决办法

    当浏览器输入访问地址后 报这样的错时----session_start(): Failed to initialize storage module 进入到此目录vi /usr/local/php/e ...

  4. C#输出日历

    用C#输出日历,此功能可用于Ajax方式列出计划日程相关的内容,由于是C#控制输出,可以方便加上自己需要的业务处理逻辑. 1.控制台输出: using System; namespace 控制台日历 ...

  5. isset函数

    isset (PHP 4, PHP 5) isset — 检测变量是否设置 检测变量是否设置,并且不是 NULL. 如果 var 存在并且值不是 NULL 则返回 TRUE,否则返回 FALSE. $ ...

  6. td里的内容宽度自适应 及 鼠标放上显示标题div title

    td里的内容自适应宽度, 用 width:100%控制 strRight+="<td bordercolor='#DEDEDE' width='500px' height='50px' ...

  7. BMP文件格式详解

    BMP文件格式详解(BMP file format) BMP文件格式,又称为Bitmap(位图)或是DIB(Device-Independent Device,设备无关位图),是Windows系统中广 ...

  8. linux git升级到1.8.3

    1. Download PUIAS repo: wget -O /etc/yum.repos.d/PUIAS_6_computational.repo https://gitlab.com/gitla ...

  9. 【servlet】 第一个servlet

    简单打印haha Helloyt.java package day01; import java.io.IOException; import javax.servlet.ServletConfig; ...

  10. opencv----彩色图像对比度增强

    图像对比度增强的方法可以分成两类:一类是直接对比度增强方法;另一类是间接对比度增强方法. 直方图拉伸和直方图均衡化是两种最常见的间接对比度增强方法. 直方图拉伸是通过对比度拉伸对直方图进行调整,从而“ ...