Discrete Square Roots UVALive - 4270(拓展欧几里得)
a≡b(mod n)的含义是“a和b除以n的余数相同”,其充要条件是“a-b是n的整数倍”;
求所有满足条件r^2=x(mod m)的r
题目已经给定了一个初始的r,x,m

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
LL N, mx, r;
set<LL> s;
LL gcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if(!b)
{
d = a;
x = ;
y = ;
}
else
{
gcd(b, a%b, d, y, x);
y -= x*(a/b);
}
} void solve(LL a, LL b)
{
LL x, y, d;
gcd(a, b, d, x, y);
if((*r) % d) return;
x *= *r/d;
x = (x % (b/d) + (b/d)) % (b/d);;
LL r1 = x*a - r;
while(r1 < N)
{
if(r1 >= && (r1*r1) % N == mx)
s.insert(r1);
r1 += a*(b/d);
}
} int main()
{
int kase = ;
while(cin>> mx >> N >> r && mx+N+r)
{
s.clear();
for(LL i=; i<=sqrt(N + 0.5); i++)
{ if(N % i) continue;
LL a = i, b = N/i;
solve(a, b);
solve(b, a);
}
printf("Case %d:",++kase);
for(set<LL>::iterator it=s.begin(); it!=s.end(); it++)
{ printf(" %lld",*it);
}
cout<<endl; } return ;
}
Discrete Square Roots UVALive - 4270(拓展欧几里得)的更多相关文章
- UVA 1426 - Discrete Square Roots(数论)
UVA 1426 - Discrete Square Roots 题目链接 题意:给定X, N. R.要求r2≡x (mod n) (1 <= r < n)的全部解.R为一个已知解 思路: ...
- NOIP2012拓展欧几里得
拉板题,,,不说话 我之前是不是说过数据结构很烦,,,我想收回,,,今天开始的数论还要恶心,一早上听得头都晕了 先来一发欧几里得拓展裸 #include <cstdio> void gcd ...
- poj 1061 青蛙的约会 拓展欧几里得模板
// poj 1061 青蛙的约会 拓展欧几里得模板 // 注意进行exgcd时,保证a,b是正数,最后的答案如果是负数,要加上一个膜 #include <cstdio> #include ...
- bzoj4517: [Sdoi2016]排列计数--数学+拓展欧几里得
这道题是数学题,由题目可知,m个稳定数的取法是Cnm 然后剩下n-m本书,由于编号为i的书不能放在i位置,因此其方法数应由错排公式决定,即D(n-m) 错排公式:D[i]=(i-1)*(D[i-1]+ ...
- POJ 2891 Strange Way to Express Integers(拓展欧几里得)
Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express ...
- POJ1061 青蛙的约会-拓展欧几里得
Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事 ...
- BZOJ-2242 计算器 快速幂+拓展欧几里得+BSGS(数论三合一)
污污污污 2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2312 Solved: 917 [Submit][S ...
- BZOJ-1407 Savage 枚举+拓展欧几里得(+中国剩余定理??)
zky学长实力ACM赛制测试,和 大新闻(YveH) 和 华莱士(hjxcpg) 组队...2h 10T,开始 分工我搞A,大新闻B,华莱士C,于是开搞: 然而第一题巨鬼畜,想了40min发现似乎不可 ...
- poj2891 拓展欧几里得
//Accepted 164 KB 16 ms //拓展欧几里得 //m=a1*x+b1 --(1) //m=a2*(-y)+b2 --(2) //->a1*x+a2*y=b2-b1 //由欧几 ...
随机推荐
- react.js插件开发,x-dailog弹窗浮层组件
react.js插件开发,x-dailog弹窗浮层组件 我认为,每一个组件都应该有他自带的样式和属性事件回调配置.所以我会给x-dialog默认一套简单的样式,和各种默认的配置项.所有react插件示 ...
- WebGL——osg框架学习三
今天继续来Draw绘制的osg模块的学习,昨天我们学习的是StateBin渲染状态树节点类,今天我们来继续学习下一个Draw的基础类DrawableEntity渲染对象实体类.这个类和Drawable ...
- python多线程与GIL(转)
作者:卢钧轶(cenalulu) 本文原文地址:http://cenalulu.github.io/python/gil-in-python/ GIL是什么 GIL(Global Interprete ...
- Oracle扩展包(pipe,alert,job,scheduler)
--定义包中函数的纯度级别 create or replace package purityTest is type dept_typ is table of dept%rowtype index b ...
- RHEL7 利用双网卡绑定实现VLAN
使用nmcli创建bond配置 #nmcli connection add type bond ifname bond0 con-name bond0 mode active-backup #nmcl ...
- 织梦调用多个栏目typeid="1,2,3"不支持的解决方法
织梦arclist调用副栏目不显示的解决办法: 打开/include/taglib/arclist.lib.php,代码约位于295-296行,查找以下两行代码: if($CrossID=='') $ ...
- 第十次ScrumMeeting博客
第十次ScrumMeeting博客 本次会议于11月5日(日)22时整在新主楼G座2楼召开,持续20分钟. 与会人员:刘畅.辛德泰.窦鑫泽.张安澜.赵奕.方科栋. 特邀嘉宾:陈彦吉学长. 1. 每个人 ...
- 使用git-premit时的问题
package.json 相关配置如下 { "scripts": { "lint": "eslint pages/* component/* --fi ...
- springboot通过http访问——修改访问的端口号
文章转载来于:https://blog.csdn.net/zknxx/article/details/53433592 有时候我们可能需要启动不止一个SpringBoot,而SpringBoot默认的 ...
- mybatis之模糊查询SQL
一,MySQL数据库 name like concat('%' , #{name} , '%') 二,Oracle数据库 name like '%' || #{name} || '%'