快速切题 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 ...
随机推荐
- SpringBoot中的Quartz应用
Spring自带定时器任务: code: import org.springframework.beans.factory.annotation.Configurable; import org.sp ...
- POJ3436 ACM Computer Factory(最大流/Dinic)题解
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8944 Accepted: 3 ...
- redhat 7.2更新yum源时踩的坑
一.update yum .先查看redhat7.2中yum的包版本 [root@localhost jiayimeng]# rpm -qa | grep yum -.el7.noarch -.el7 ...
- MOOC_Java进阶_翁恺讲_第三周题
package mooc_java进阶_d3周题; /** * 没有使用HashMap */ import java.util.ArrayList; import java.util.Scanner; ...
- Nlog、elasticsearch、Kibana以及logstash在项目中的应用(二)
上一篇说如何搭建elk的环境(不清楚的可以看我的上一篇博客http://www.cnblogs.com/never-give-up-1015/p/5715904.html),现在来说一下如何用Nlog ...
- NOI 8467 鸣人的影分身
http://noi.openjudge.cn/ch0206/8467/ 描述 在火影忍者的世界里,令敌人捉摸不透是非常关键的.我们的主角漩涡鸣人所拥有的一个招数——多重影分身之术——就是一个很好的例 ...
- ubuntu 14.04 server(amd64) 安装ros indigo
1.添加软件源(添加了正确的软件源,操作系统就知道去哪里下载程序,并根据命令自动安装软件) sudo sh -c 'echo "deb http://packages.ros.org/ros ...
- Charles Proxy License 破解
// Charles Proxy License // 适用于Charles任意版本的注册码,谁还会想要使用破解版呢. // Charles 4.2目前是最新版,可用. Registered Na ...
- Python day13文件的读写
# 文件操作 f=open("E:\\1.txt",encoding="GBK")#打开文件 print(f.writable())#是否可写 print(f. ...
- pyHook监听用户鼠标、键盘事件
一.代码部分:获取用户输入信息,并与截图一起保存到XX目录下 # -*- coding: utf-8 -*- # import pythoncom import pyHook impor ...