数论 - 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 ...
随机推荐
- (剑指Offer)面试题52:构建乘积数组
题目: 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1].不能 ...
- Java内存溢出的详细解决方案(转http://developer.51cto.com/art/200906/129346.htm)
一.内存溢出类型 1.java.lang.OutOfMemoryError: PermGen space JVM管理两种类型的内存,堆和非堆.堆是给开发人员用的上面说的就是,是在JVM启动时创建:非堆 ...
- 很全的Python 面试题 github
https://github.com/taizilongxu/interview_python
- ReSharper的功能真的很强大主要是针对代码规范和优化,园子里介绍的也不少,如果你没有安装,那我只能表示你们会相见恨晚
二.ReSHarper 代码规范.单元测试.... ReSharper的功能真的很强大,主要是针对代码规范和优化,园子里介绍的也不少,如果你没有安装,那我只能表示你们会相见恨晚! 1.像命名不规范,f ...
- java防止sql注入
public final static String filterSQLInjection(String s) { if (s == null || "".equals(s)) { ...
- Google C++ Coding Style 学习笔记
写在前面:最新公司马上就要开始开发一款视觉产品,工程量较大,且需要对客户提供可以二次开 发的SDK,整个项目用C++编写. 这就对代码质量提出了非常高的要求,同时,如何设计出优雅稳定的API也是相当大 ...
- JDBC 可更新和对更新敏感的结果集
public class OtherApi { /** * @param args * @throws SQLException * @throws Interr ...
- sphinx和mysql like对比
一共有3093326条企业数据,其中sphinx代码如下: <?php function microtime_float() { list($usec, $sec) = explode(&quo ...
- 在ASP.Net和IIS中删除不必要的HTTP响应头[转]
http://www.cnblogs.com/CareySon/archive/2009/12/14/1623624.html 引入 每次当浏览器向Web服务器发起一个请求的时,都会伴随着一些HTTP ...
- 安卓编译报错:Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
今天在编译别人的project时遇到了这个错误,心想应该不是代码的问题.网上搜了一下,应该是sdk版本设置的问题,要设置为最新sdk版本才可以. 解决办法就是修改project.properties里 ...