不理解,背板子

#include<cstdio>

using namespace std;

int Pow(int a,int b,int p)
{
int res=;
for(;b;a=1LL*a*a%p,b>>=)
if(b&) res=1LL*a*res%p;
return res;
} bool Legendre(int a,int p)
{
return Pow(a,p->>,p)==;
} void modsqr(int a,int p)
{
int x;
int i,k,b;
if(p==) x=a%p;
else if(p%==) x=Pow(a,p+>>,p);
else
{
for(b=;Legendre(b,p);++b);
i=p->>;
k=;
do
{
i>>=;
k>>=;
if(!((1LL*Pow(a,i,p)*Pow(b,k,p)+)%p)) k+=p->>;
}while(!(i&));
x=1LL*Pow(a,i+>>,p)*Pow(b,k>>,p)%p;
}
if(p-x<x) x=p-x;
if(x==p-x) printf("%d\n",x);
else printf("%d %d\n",x,p-x);
} int main()
{
freopen("data.txt","r",stdin);
freopen("aa.txt","w",stdout);
int T;
scanf("%d",&T);
int a,n;
while(T--)
{
scanf("%d%d",&a,&n);
a%=n;
if(!Legendre(a,n))
{
puts("No root");
continue;
}
modsqr(a,n);
}
return ;
}

Timus 1132 Square Root(二次剩余 解法2)的更多相关文章

  1. Timus 1132 Square Root(二次剩余)

    http://acm.timus.ru/problem.aspx?space=1&num=1132 题意: 求 x^2 ≡ n mod p  p是质数 的 解 本题中n>=1 特判p=2 ...

  2. URAL 1132 Square Root(二次剩余定理)题解

    题意: 求\(x^2 \equiv a \mod p\) 的所有整数解 思路: 二次剩余定理求解. 参考: 二次剩余Cipolla's algorithm学习笔记 板子: //二次剩余,p是奇质数 l ...

  3. Codeforces 715A. Plus and Square Root[数学构造]

    A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Project Euler 80:Square root digital expansion 平方根数字展开

    Square root digital expansion It is well known that if the square root of a natural number is not an ...

  5. Codeforces 612E - Square Root of Permutation

    E. Square Root of Permutation A permutation of length n is an array containing each integer from 1 t ...

  6. Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))

    C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

  8. Square Root

    Square RootWhen the square root functional configuration is selected, a simplified CORDIC algorithm ...

  9. Codeforces Round #372 (Div. 1) A. Plus and Square Root 数学题

    A. Plus and Square Root 题目连接: http://codeforces.com/contest/715/problem/A Description ZS the Coder i ...

随机推荐

  1. Linux服务器定时健康检查,发生故障自动微信告警

    此脚本适用于于各种Linux环境,可以实现各种监控项目,可自定义阀值,实现不同监控效果已在原有脚本基础上做了简化,提取了主要功能目前实现的有:1.磁盘监控2.内存监控3.cpu负荷监控4.进程数监控5 ...

  2. 搭建本地yum源并定时同步

    在生产中内网的机器都是不能访问外网,所以需要搭建本地yum源.以中国科学科技大学的yum源为基准.http://mirrors.ustc.edu.cn/ 有些模块会同步失败,可以wget下载至指定位置 ...

  3. js中获取css样式属性值

    关于js中style,currentStyle和getComputedStyle几个注意的地方 (1)用js的style只能获取元素的内联样式,内部样式和外部样式使用style是获取不到的.针对css ...

  4. 如何减少UI设计师产品与前端工程师的沟通成本

    在日常工作中,UI设计师/产品与前端工程师难免会有一些冲突,这是我的一些小建议. 1.如何减少时间成本 先制作UI组件,再拼接页面 如果UI给前端的是一堆页面,前端需要花一些时间去整理提取UI组件.另 ...

  5. ES6中箭头函数与普通函数this的区别

    普通函数中的this: 1. this总是代表它的直接调用者, 例如 obj.func ,那么func中的this就是obj 2.在默认情况(非严格模式下,未使用 'use strict'),没找到直 ...

  6. python 逻辑运算符问题

    1 正确 if('A' not in self.storageDevice.softVersion or\ 'B' not in self.storageDevice.softVersion or\ ...

  7. luogu3674 小清新人渣的本愿 (bitset+莫队)

    对于加减,用bitset维护当前每个数有没有 对于乘,暴力枚举约数 然后莫队 复杂度$O(m(\sqrt{n}+\frac{c}{64}))$ #include<bits/stdc++.h> ...

  8. LOJ#6277. 数列分块入门 1

    分块思想,先把原来的序列分成根号n快,然后对于更新的部分,先操作这个序列边上的部分,然后再中间部分整块操作,这样复杂度就是O(根号N) #include<map> #include< ...

  9. 【nginx】nginx配置文件结构,内置变量及参数调优

    Nginx的配置文件是一个纯文本文件,它一般位于Nginx安装目录的conf目录下,整个配置文件是以block的形式组织的.每个block一般以一个大括号“{”来表示.block 可以分为几个层次,整 ...

  10. LOJ#2720 你的名字

    题意:给定母串s和若干个询问.每个询问是一个串t和两个数l,r,表示求t中有多少个本质不同的子串没有在s[l,r]中出现过. 解:我写的并不是正解......是个毒瘤做法.只在loj上面卡时过了就写l ...