快速切题 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 ...
随机推荐
- 0x30、0x37
1.write_date(0x30+shi)加0x30是什么意思 答: 将数字0-9转化为字符'0'-'9' 1.write_date(0x37+bai)加0x37是什么意思 答: 将大于9的数字转化 ...
- STM32各个文件介绍、uCOSII文件介绍
(1)core_cm3.c , core_cm.h:获取设置CM3内核,配置一些内核寄存器,用到CM3核的都需要: (2)stm32f10x.h 和 system_stm32f10x.c , syst ...
- IDEA中使用.ignore插件忽略不必要提交的文件
使用的IDE是IntelliJ IDEA,发现IDEA在提交项目到本地仓库的时候,会把.idea文件夹中的内容也提交上去,这里面放的是一些项目的配置信息,包括历史记录,版本控制信息等.可以不传到Git ...
- 为 Android 8.0 添加开机启动脚本【转】
本文转载自:https://zhuanlan.zhihu.com/p/32868074 本人对于 SELinux for Android 理解不深,下文中的各文件及安全规则虽都是我所编写,但也是一边查 ...
- github issues的操作
https://help.github.com/en/articles/searching-issues-and-pull-requests 根据 reporter筛选issues https://h ...
- 华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列
Problem G: Array C Time Limit: 1 Sec Memory Limit: 128 MB Description Giving two integers and and ...
- poj 1986 Distance Queries 带权lca 模版题
Distance Queries Description Farmer John's cows refused to run in his marathon since he chose a pa ...
- shell 清空指定大小的日志文件
#!/bin/bash # 当/var/log/syslog大于68B时 if ! [ -f /var/log/syslog ] then echo "file not exist!&quo ...
- Java DecimalFormat的主要功能及使用方法
DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数字.该类设计有各种功能,使其能够分析和格式化任意语言环境中的数,包括对西方语言.阿拉伯语和印度语数字的支持. ...
- Linux忘记root登录密码解决方法
有时候由于长时间米有登录linux系统,等需要用的时候突然忘记root密码,怎么办?下面简单介绍解决方法. redhat 和 centos 6.5 可以,7.0以上未测 在系统重启后,不停地按”e”键 ...