sgu119
来源:互联网 发布:淘宝客服怎么手机登录 编辑:程序博客网 时间:2024/05/23 17:57
题目:
119. Magic Pairs
time limit per test: 0.25 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
31 2
Sample Output
3 0 01 22 1
Author: Michael R. MirzayanovResource: PhTL #1 Training ContestsDate: Fall 2001题解:
由某些结论我们得知:A=(k*A0)%n, B=(k*b0)%n,然后直接排序输出即可
代码:
#include<cstdio>#include<cstdlib>#include<vector>#include<algorithm>#include<iostream>#include<iterator>using namespace std;typedef pair<int, int> pp;vector<pp> ans;int A, B, n;int main(){scanf("%d%d%d", &n, &A, &B);A %= n;B %= n;int a = A, b = B;do{a = (a + A) % n;b = (b + B) % n;ans.push_back(make_pair(a, b));}while (a != A || b != B);printf("%d\n", ans.size());sort(ans.begin(), ans.end());vector <pp>::iterator it;for (it = ans.begin(); it != ans.end(); it++) printf("%d %d\n", it->first, it->second);return 0;}话说用vector这种东西也不是太熟练,到网上查的。。。
- sgu119
- sgu119
- sgu119:Magic pairs
- SGU119 Magic Pairs
- SGU 水题集3 SGU116 SGU117 SGU118 SGU119
- 使用Intent的好处、回调的含义
- Atitit.编程语言的主要的种类and趋势 逻辑式语言..函数式语言...命令式语言
- JavaScript事件模型
- UIPFULL!DllCanUnloadNow崩溃问题解决
- 1.把二元查找树转变成排序的双向链表
- sgu119
- android实现双击事件暨多击事件详解
- maven 各类问题汇总
- Foundation框架基础 NSMutableDictionary-可变字典
- 黑马程序员-提示用户输入一个正整数n,计算1-2+3-4+5-6+…+n的和 #include <stdio.h>
- 文档处理 复制
- 黑马程序员-iOS基础-C语言基础(三)流程控制及函数
- 如何设置Matlab输出到Word中图片的大小
- 网站要想获得好排名四个必要条件