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的更多相关文章

  1. SGU 119.Magic pairs

    题意: 对于给出的一个整数N,和一对(A0,B0) 找到所有的整数对(A,B)满足 : 对于任意 X,Y 当 A0 * X + B0 * Y 能被 N 整除时 A * X + B * Y 也能被 N ...

  2. 快速切题 sgu119. Magic Pairs

    119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...

  3. 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* ...

  4. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  5. Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)

    Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...

  6. 数论 - Pairs(数字对)

    In the secret book of ACM, it’s said: “Glory for those who write short ICPC problems. May they live ...

  7. (第三场) H Diff-prime Pairs 【数论-素数线性筛法+YY】

    题目链接 题目描述 Eddy has solved lots of problem involving calculating the number of coprime pairs within s ...

  8. 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 ...

  9. Ural 2003: Simple Magic(数论&思维)

    Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is e ...

随机推荐

  1. div+css 和 xhtml+css是一回事么?

    div+css 和 xhtml+css是一回事.只是说法不一样,表达得意思都是通过CSS定义DIV 布局. 那为什么地方要说成XHTML +css 呢? 以为我们做网站用CSS布局得时候不光是用了DI ...

  2. 出现RST的几种情况

    1.端口未打开,C向S发送SYN,去连接S的端口9820,但是S没有打开9820端口,这个时候S发送RST 2.请求超时,C向S发送SYN,S回复ACK+SYN,如果C从发送SYN到收到S的ACK+S ...

  3. ASP站点无法访问怎么办

    确保启用了目录浏览功能

  4. windows下flv视频网站进度条随意拖放[转]

    网站中视频都转换成flv格式,奈何flv格式无法拖拽,此问题纠结了好久,最终得以解决.现将解决思路记录下来,大多数源于网上找到的. 视频拖拽满足要求 1.播放器要支持 2.flv视频要有关键帧和met ...

  5. Project Euler:Problem 76 Counting summations

    It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...

  6. 搭建ssm+maven环境遇到的问题

    1. @RunWith(SpringJUnit4ClassRunner.class) gives error 在使用junit测试过程中 2.com.google.gson.JsonIOExcepti ...

  7. 查看cache中消耗性能的语句

    sqlserver服务器内存偏高,查看下cache中sql消耗情况! /* 查询cache中的语句 说明:可以根据类型.用户数.大小查询 */ ) declare @usecounts int dec ...

  8. bzoj-1492 货币兑换Cash (2)——CDQ分治

    题意: 略 见上一篇 题解: 方程还是那个方程f[i]=A[i] * X[j] + B[i] * Y[j]. 化简为Y[i]=(-A[i]/B[i]) * X[i] + f[i]/B[i]这一坨: 既 ...

  9. EL函数库

    一.EL函数库介绍 由于在JSP页面中显示数据时,经常需要对显示的字符串进行处理,SUN公司针对于一些常见处理定义了一套EL函数库供开发者使用. 这些EL函数在JSTL开发包中进行描述,因此在JSP页 ...

  10. JDBC JdbTemplate&NamedParameterJdbcTemplate(Spring工具类)

    使用该工具类需要从spring开发包中导入spring.jar和commons-logging.jar,这个模板是线程安全的.   JdbcTemplate: public class JdbcTem ...