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). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell . The following condition is satisfied for the vector: , where is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.

Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.

Input

The first line contains integers n, m, dx, dy(1 ≤ n ≤ 106, 1 ≤ m ≤ 105, 1 ≤ dx, dy ≤ n) — the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 ≤ xi, yi ≤ n - 1) — the coordinates of apples. One cell may contain multiple apple trees.

Output

Print two space-separated numbers — the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.

Sample test(s)
input
C++
5 5 2 3
0 0
1 2
1 3
2 4
3 1
1
2
3
4
5
6
5 5 2 3
0 0
1 2
1 3
2 4
3 1
output
C++
1 3
1
1 3
input
C++
2 3 1 1
0 0
0 1
1 1
1
2
3
4
2 3 1 1
0 0
0 1
1 1
output
C++
0 0
1
0 0
Note

In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)

In the second sample: (0, 0) - (1, 1) - (0, 0)

【分析】

这道题目相对比较简单了。

题意:在一个n * n的棋盘上,有m棵给定坐标的苹果树,选定一个起点(x, y),每次以横坐标+dx(mod n),纵坐标 +dy(mod n)的形式进行移动,其中gcd(dx, n) = gcd(dy, n) = 1,询问选择哪个起点能经过最多的苹果树?

因为有gcd(dx, n) = gcd(dy, n) = 1 所以可以得知行走的路线一定是一个循环,并且循环的长度为n,且能够经过每一个x坐标和每一个y坐标。

我们不妨将起点设在x为0的位置,然后预处理出到其他的x坐标所需要变化的y值,然后就可以将苹果树进行"平移"到x坐标为0上,然后就可以做了。

【CF492E】【数学】Vanya and Field的更多相关文章

  1. 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 ...

  2. cf492E Vanya and Field

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

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

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

  4. Vanya and Field

    Vanya and Field 题目链接:http://www.codeforces.com/problemset/problem/492/E 逆元 刚看到这题的时候一脸懵逼不知道从哪下手好,于是打表 ...

  5. codeforces 492E. Vanya and Field(exgcd求逆元)

    题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...

  6. 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 ...

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

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

  8. Codeforces 492E Vanya and Field

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

  9. cf492E. Vanya and Field(扩展欧几里得)

    题意 $n \times n$的网格,有$m$个苹果树,选择一个点出发,每次增加一个偏移量$(dx, dy)$,最大化经过的苹果树的数量 Sol 上面那个互素一开始没看见,然后就GG了 很显然,若$n ...

随机推荐

  1. CodeForces 352D. Jeff and Furik

    题意:给n个数,第一个人选取相邻两个递降的数交换顺序,第二个人一半的概率选取相邻两个递降的数交换顺序,一半的概率选取相邻两个递增的数交换顺序.两个人轮流操作,求整个数列变成递增数列所需交换次数的期望. ...

  2. linux文件权限查看及修改-chmod

    查看linux文件的权限:ls -l 文件名称 查看linux文件夹的权限:ls -ld 文件夹名称(所在目录) 修改文件及文件夹权限: sudo chmod -(代表类型)×××(所有者)×××(组 ...

  3. linux多线程编程(转)

    原文地址:http://www.cnblogs.com/BiffoLee/archive/2011/11/18/2254540.html 1.Linux“线程” 进程与线程之间是有区别的,不过Linu ...

  4. Learning JavaScript Design Patterns The Observer Pattern

    The Observer Pattern The Observer is a design pattern where an object (known as a subject) maintains ...

  5. 来自奢侈品行业的CEO能给苹果带来什么?

    重回苹果的奢侈品大佬:保罗丹诺威 作为伊夫·圣罗兰(Saint Laurent)时尚集团的前CEO,保罗丹诺威(Paul Deneve)9月将正式加入苹果公司,并负责该公司所谓的“特殊项目”,同时直接 ...

  6. php数组相加 两个数组键名相同 后者不能覆盖前者

    array(“a”)+array(“b”)结果还是array(“a”) array(“a”)+array(“b”)的结果是 array(“a”) 因为,它们等效于array(“0″=>”a”)+ ...

  7. SqlServer表中两条全然同样的记录,怎样删除当中1条

    描写叙述:表无主键ID,误插入两遍数据,怎样删除内容同样的记录,而仅仅留下1条. SELECT DISTINCT * INTO #temp FROM grade; DROP TABLE grade; ...

  8. [OGRE]基础教程来七发:来谈一谈缓冲绑定

    上一章我们处理监听的方案是,每一帧只处理一次. 这一次,当鼠标键盘的事件发生时,我们会立即处理它. 这里只是对缓冲输入的一个简单介绍,而不是完整的如何使用OIS的教程. 若想了解更多内容,请查阅相关的 ...

  9. android弧形进度条,有详细注释的,比较简单

    Java code? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...

  10. android109 结构体,联合体,枚举,自定义

    #include <stdio.h> #include <stdlib.h> void study(){ printf("吃饭睡觉打李志\n"); } // ...