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. glusterfs 术语

    Access Control Lists Access Control Lists (ACLs) allows you to assign different permissions for diff ...

  2. POJ3107--Godfather(树的重心)

    vector建图被卡了..改为链式前向星500ms过的..差了四倍多?... 表示不太会用链表建图啊..自己试着写的,没看模板..嗯..果然错了..落了一句话orz 树的重心就是找到一个树中一个点,其 ...

  3. Redis常用数据类型

    Redis常用数据类型 转载自:http://blog.sina.com.cn/s/blog_7f37ddde0101021q.html     Redis最为常用的数据类型主要有以下五种: ●Str ...

  4. Android源码是这样搞到的(图解)

    Android学习到一定程度,就一定要多读代码多思考,Android源码就是很好的学习材料,本文就是把Android的源码下载下来.我们知道Android的源码是用Git这个分布式版本号控制工具管理的 ...

  5. Tsar 服务器系统和应用信息的采集报告工具

    Tsar介绍 Tsar是淘宝的一个用来收集服务器系统和应用信息的采集报告工具,如收集服务器的系统信息(cpu,mem等),以及应用数据(nginx.swift等),收集到的数据存储在服务器磁盘上,可以 ...

  6. 【转】cocos2d-x 模仿计时器效果,动态增加分数——2013-08-25 16

    http://www.cocos2dev.com/?p=90 游戏中要用到分数是动态增加的,而不是瞬间加上去的. bool HelloWorld::init() { if ( !CCLayer::in ...

  7. 嵌入式Qt4.7.1安装详解

    嵌入式Qt 4.7.1安装移植过程详解环境:Ubuntu 12.04VMware 9.0 qt软件包:qt-everywhere-opensource-src-4.7.1.tar.gz (飞凌自带) ...

  8. 获取java项目 classpath目录

    this.getClass().getResource("/").getPath(); 从根目录获取载入文件: this.getClass().getResourceAsStrea ...

  9. Android(java)学习笔记143:android提供打开各种文件的API接口:setDataAndType

    android 打开各种文件(setDataAndType) private void openFile(File file){ Intent intent = new Intent(); inten ...

  10. Nexus搭建Maven服务器

    参考:http://blog.csdn.net/ichsonx/article/details/14642897 1. 为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央 ...