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. DOSbox汇编集成环境下的具体设置

    alt+enter能够全屏幕,假设认为游戏执行速度不合适,能够改动 cycles=3000 适当调整大小. .执行 DOSBox,会打开两个 DOS 窗体.我们仅仅需在例如以下窗体中键入 mount ...

  2. 解压zip,解决中文乱码

    Project p = new Project();        Expand e = new Expand();        e.setProject(p);        e.setSrc(f ...

  3. SQL SERVER: 合并相关操作(Union,Except,Intersect)

    SQL SERVER: 合并相关操作(Union,Except,Intersect) use tempdb create table tempTable1 (id int primary key id ...

  4. JDBC 关于大文本数据

    大文本数据Clob,在不同的数据库中类型名不一致,有的是text格式,有的是clob,还有其他一些格式   package test; import java.io.BufferedReader; i ...

  5. 使用Eclipse构建Maven项目 (step-by-step) (转收藏)

    Maven这个个项目管理和构建自动化工具,越来越多的开发人员使用它来管理项目中的jar包.本文仅对Eclipse中如何安装.配置和使用Maven进行了介绍.完全step by step. 如果觉得本文 ...

  6. ORA-12519:数据的连接池访问过多

    今天服务部同事问我一个问题,客户处的报表一半能打开,一半报错如下: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=185599744)(ERR ...

  7. Ubuntu下添加新分区并设置挂载点

    Ubuntu下添加新分区并设置挂载点   最近在做Android项目,可是解压根文件系统以后,就报警说硬盘不够.当初设置使用的大小为15G.不过扩展分区还是很方便的.当然首先你得设置添加使用的硬盘大小 ...

  8. numpy.argmin 使用

    https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.argmin.html numpy.argmin(a, axis=N ...

  9. Python 爬虫实例(2)—— 爬取今日头条

    # coding:utf-8 import base64 import random, re import sqlite3 import redis, pickle import json, time ...

  10. SQL Server 2008、SQL Server 2008R2 自动备份数据库

    让SQL Server 2008自动备份数据库,需要建立一个SQL Server作业,并启动SQL Server代理,使该作业定期运行. 具体来说,可以按以下步骤进行: 一.打开SQL Server ...