数论 - 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 ...
随机推荐
- Maven项目结合POI导出Excl表格Demo-亲测可用
Maven项目结合POI导出Excl表格 一.POM文件添加依赖 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> ...
- C#基础视频教程7.3 如何编写简单游戏
前面我们大致实现了鸟的一圈轨迹(其实如果你不做这个,就用两个矩形块的碰撞检测代替也可以),跟所有前面的教程一样,草稿打完了就要设计封装成一个类.至少到目前为止我们已经知道了鸟的属性和方法,先不要管方法 ...
- ssh登陆不上
用ssh key登陆不上某台机A的某个账号xy1,查看A的/var/log/messages,看到有这么句: User xy1 not allowed because account is locke ...
- JQuery 之CSS操作
JQuery 之CSS操作 设置 <p> 元素的颜色: 将所有段落的颜色设为红色 $(".btn1").click(function(){ $("p" ...
- iOS网络监控— BMReachability
1. What's BMReachability? BMReachability是基于AFNetworking的Reachability类封装的监听网络状态变化的组件. 它在AF提供的无网络/wifi ...
- 关于图片无缝拼接的学习(PTGui)
一.简介 在用到单反.无人机.手机等拍照工具,需要无缝拼接. 二.下载 官网:http://www.ptgui.com/download.html 其他:http://pan.baidu.com/sh ...
- linux之进程管理详解
|-进程管理 进程常用命令 |- w查看当前系统信息 |- ps进程查看命令 |- kill终止进程 |- 一个存放内存中的特殊目 ...
- UML基本架构建模--类的辅助信息
Organizing Attributes and Operations 组织属性和操作 When drawing a class, you don't have to show every attr ...
- 转:【微信小程序】实现锚点定位楼层跳跃的实例
微信小程序实现楼层锚点跳跃,点击不同的锚点进行位置跳跃: 利用:scroll-into-view 来实现: 效果图: wxml: <scroll-view class="cont ...
- Linux索引节点(Inode)用满导致空间不足
一.问题出现 在创建新目录和文件是提示“no space left on device”!按照以前的情况,很有可能是服务器空间又被塞满了,通过命令查看,发现还有剩余.再用df -i查看了一下/分区的索 ...