题目链接: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. 模拟post请求-->测试api是否可用-->再交给ios开发

    提交给iso开发前.先模拟post提交,测试返回是否正确 =============post.php文件 ios每次最少要提交5个数据, 加密串 seqno , 请求验证码 source, 设备唯一标 ...

  2. 构造DataTable

    手动构造一个DataTable: DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(string)); dt. ...

  3. Git 版本管理基本操作

    Git是一个版本管理操作的工具 非常N,可以很智能的分布式管理, 本网站学习笔记 来自于廖雪峰老师的内容借鉴 安装 yum -y install git 本地设置全局 告知是谁提交代码 信息 # gi ...

  4. C++设计模式-Singleton单例模式

    template <typename T> class Singleton { public: template <typename... Args> static T* In ...

  5. JS学习之动态加载script和style样式

    前提:我们可以把一个网页里面的内容理解为一个XML或者说网页本身也就是一个XML文档,XML文档都有很特殊的象征:"标签"也叫"节点".我们都知道一个基本的网页 ...

  6. Gym 100917C Constant Ratio 数论+暴力

    题目: Description standard input/outputStatements Given an integer n, find out number of ways to repre ...

  7. 初探JavaScript魅力(四)

    选项卡 <title>无标题文档</title> <style> #div1 .active{background:#FF0;} #div1 div{width:2 ...

  8. 设置批量商品优惠、如何修改ZenCart产品显示图片的大小

    利用下面的方法,可以实现: 买一送一.买一件第二件5折.买三件优惠10%等功能. 管理页面 - 商品管理 - 价格管理 - (选择商品) - 编辑 - 添加空白折扣. 应用上面的办法,能够完成:买一送 ...

  9. MaterialDrawer的使用

    这是一个MaterialDesign风格的侧滑,在github上下载压缩包,按照github上的方式引入依赖,然后打开压缩包里面的例子程序,对照着APK看,即可知道怎么实现的(好像说了一堆废话..)

  10. mysql 创建数据 utf8

    CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;