数论 - 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<N)
analyse:
这道题目就是先把A0和B0和N都除以他们的最大公约数,然后就是枚举A0和B0的0到N-1倍.
最后快排,注意一下有0的情况.
Time complexity: O(N)
view code
/**
* -----------------------------------------------------------------
* Copyright (c) 2016 crazyacking.All rights reserved.
* -----------------------------------------------------------------
* Author: crazyacking
* Date : 2016-01-08-10.51
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-); int main()
{ pair<int, int> ans[];
int n,a0,b0;
scanf("%d%d%d",&n,&a0,&b0); int i = a0 %= n;
int j = b0 %= n;
int num = ; do
{
ans[num++] = make_pair(i, j);
i = (i+a0)%n;
j = (j+b0)%n;
}
while(i != a0 || j != b0); sort(ans, ans+num);
printf("%d\n",num);
for(i = ; i < num; i++)
printf("%d %d\n",ans[i].first,ans[i].second); return ;
}
数论 - 119. Magic Pairs的更多相关文章
- SGU 119.Magic pairs
题意: 对于给出的一个整数N,和一对(A0,B0) 找到所有的整数对(A,B)满足 : 对于任意 X,Y 当 A0 * X + B0 * Y 能被 N 整除时 A * X + B * Y 也能被 N ...
- 快速切题 sgu119. Magic Pairs
119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...
- 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 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...
- 数论 - Pairs(数字对)
In the secret book of ACM, it’s said: “Glory for those who write short ICPC problems. May they live ...
- (第三场) H Diff-prime Pairs 【数论-素数线性筛法+YY】
题目链接 题目描述 Eddy has solved lots of problem involving calculating the number of coprime pairs within s ...
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field【数论/组合数学】
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input ...
- Ural 2003: Simple Magic(数论&思维)
Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is e ...
随机推荐
- 《Go并发编程实战》第2版 紧跟Go的1.8版本号
文章作者:郝林(<Go并发编程实战 (第2版)>作者) 最终来了! 经过出版社的各位编辑.校对.排版伙伴与我的N轮PK和共同努力,<Go并发编程实战>第2版的全部内容最终全然确 ...
- 推荐一个在线json数据格式化网站
json数据非常友好方便的处理: 推荐一个在线json数据格式化网站 http://json.parser.online.fr/
- Spring Boot学习记录(二)–thymeleaf模板
自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好 ...
- SyntaxError: Non-UTF-8 code starting with '\xc5' in file t.py on line 3,but no encoding declared;see http://python.org/dev/peps/pep-0263/ for details
解决方案是: 在程序最上面加上:# coding=gbk 这样程序就可以正常运行了.
- react-router-dom Link search 传参
<Link> 和之前版本没太大区别,重点看下组件属性: to(string/object):要跳转的路径或地址: replace(bool):为 true 时,点击链接后将使用新地址替换掉 ...
- 《学习opencv》笔记——矩阵和图像操作——cvCrossProduct and cvCvtColor
矩阵和图像的操作 (1)cvCrossProduct函数 其结构 void cvCrossProdust(//计算两个三维向量的叉积 const CvArr* src1, const CvArr* s ...
- iOS 3DTouch
概述 iOS10系统登录中国,在系统中对3D Touch的使用需求更频繁,所以对iOS9中便引入的3D Touch功能做一些了解是很有必要的 详细 代码下载:http://www.demodashi. ...
- Python-多线程学习总结
我们在做软件开发的时候很多要用到多线程技术.例如如果做一个下载软件象flashget就要用到.象在线视频工具realplayer也要用到因为要同时下载media stream还要播放.其实例子是很多的 ...
- 卓有成效的团队建设经验与见解 Team Leader你会带团队吗?
http://www.nowamagic.net/librarys/veda/detail/1955前言 这篇文章是写给Team Leader和往这个方向前进的人.也适合一般的程序员,对你们在团队合作 ...
- 转 Android Activity之间动画完整版详解
标签:Android Activity动画详解 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://mzh3344258.blog.5 ...