快速切题 sgu119. Magic Pairs
119. Magic Pairs
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
“Prove that for any integer X and Y if 5X+4Y is divided by 23 than 3X+7Y is divided by 23 too.” The task is from city Olympiad in mathematics in Saratov, Russia for schoolchildren of 8-th form. 2001-2002 year.
For given N and pair (A0, B0) find all pairs (A, B) such that for any integer X and Y if A0X+B0Y is divided by N then AX+BY is divided by N too (0<=A,B<N).
Input
Each input consists of positive integer numbers N, A0 and B0 (N,A0,B0£ 10000) separated by whitespaces.
Output
Write number of pairs (A, B) to the first line of output. Write each pair on a single line in order of non-descreasing A (and B in case of equal A). Separate numbers by single space.
Sample Input
3
1 2
Sample Output
3
0 0
1 2
2 1
//started 22:24
//read error 1 23:15
//read answer 0:41 晕,既然a0x+b0y|n,ax+by|k*n,直接乘上k再modn即可....
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int extgcd(int a,int b,int &x,int &y){
int d=a;
if(b!=0){
d=extgcd(b,a%b,y,x);
y-=(a/b)*x;
}
else {
x=1;y=0;
}
return d;
}
typedef pair<int ,int> P;
P heap[10001];
int cnt;
int main(){
int n,a0,b0;
scanf("%d%d%d",&n,&a0,&b0);
int ty,tx,tmp1,tmp2;
int abgcd=extgcd(a0,b0,tx,ty);
int nabgcd=extgcd(abgcd,n,tmp1,tmp2);
n=n/nabgcd;
a0=a0/nabgcd;
b0=b0/nabgcd;
for(int i=0;i<n;i++){
int a=a0*i%n;
int b=b0*i%n;
heap[i]=P(a,b);
}
sort(heap,heap+n);
printf("%d\n",n);//必然有n个解
for(int i=0;i<n;i++){
printf("%d %d\n",heap[i].first*nabgcd,heap[i].second*nabgcd);
}
return 0;
}
快速切题 sgu119. Magic Pairs的更多相关文章
- 数论 - 119. Magic Pairs
Magic Pairs Problem's Link Mean: 已知N.A0.B0,对于给定X.Y,若A0X+B0Y能被N整除,则AX+BY也能被N整除,求所有的A.B.(0<=A.B< ...
- Magic Pairs - SGU 119(同余)
题目大意:如果A0*X + B0*Y能够整除 N,求出来多有少A*X+B*Y 也能够整除去N,求出所有的A,B(0<=A,B<N) 分析:有条件可以知道 A*X+B*Y = K *(A0* ...
- SGU 119.Magic pairs
题意: 对于给出的一个整数N,和一对(A0,B0) 找到所有的整数对(A,B)满足 : 对于任意 X,Y 当 A0 * X + B0 * Y 能被 N 整除时 A * X + B * Y 也能被 N ...
- 快速切题sgu127. Telephone directory
127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 快速切题 sgu123. The sum
123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...
- 快速切题 sgu120. Archipelago 计算几何
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...
- 快速切题 sgu118. Digital Root 秦九韶公式
118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...
- 快速切题 sgu117. Counting 分解质因数
117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...
随机推荐
- 移动页面click延迟引发的touch问题
一.事件捕获与冒泡 先扯一下事件的触发流程,这个之后会用到. DOM2级事件规定事件包括三个阶段: ① 事件捕获阶段 ② 处于目标阶段 ③ 事件冒泡阶段 大概的流程就是事件从最外层一层一层往里面传递( ...
- SC命令---安装、开启、配置、关闭windows服务 bat批处理(转载)
转载:http://www.jb51.net/article/49627.htm 转载:http://blog.csdn.net/c1520006273/article/details/5053905 ...
- C++11标准 STL正则表达式 验证电子邮件地址
转自:http://www.cnblogs.com/yejianfei/archive/2012/10/07/2713715.html 我们最经常遇到的验证,就是电子邮件地址验证.网站上常见.各种网页 ...
- 数据结构-队列(3)-使用Java内置队列
大多数流行语言都提供内置的队列库,因此您无需重新发明轮子. 如前所述,队列有两个重要的操作,入队 enqueue 和出队 dequeue. 此外,我们应该能够获得队列中的第一个元素,因为应该首先处理它 ...
- String和int互相转换,String转float
String-->int int a=Integer.parseIn(str); int-->String String s= a+""; String-->fl ...
- 【附12】grafana配置文件
一.配置文件位置 /usr/local/opt/grafana/share/grafana/default.ini /usr/local/etc/grafana/grafana.ini 二.init格 ...
- each遍历小结
JQ中的遍历函数 (逐个加工函数) 格式: $(‘.box p’).each(function(index,element){ })也可以写成 $.each(‘.box p’,function(ind ...
- 软件测试&安全测试高峰论坛
Nubia测试以及介绍 基于Cucumber的自动化测试平台 常见Web漏洞之XSS,主要HTML与JS基础.XSS的基础知识与挖掘方法.XSS的利用 自动化测试框架以及测试思路
- spoj TBATTLE 质因数分解+二分
题目链接:点击传送 TBATTLE - Thor vs Frost Giants #number-theory #sliding-window-1 Thor is caught up in a fie ...
- python input输入元素相加
sum= number= while True: : break number=int(input('数字0为结束程序,请输入数字: ')) sum+=number print('目前累加的结果为: ...