不理解,背板子

#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. 【XSY2709】count DP

    题目描述 有一个序列\(A\),你可以随意排列这个序列,设\(s=\sum_{i=1}^{n-1}|a_i-a_{i+1}|\) . 问你最终\(s\leq m\)的方案数有几种. 保证\(A\)中的 ...

  2. DNSCrypt

    DNSCrypt 来源 https://www.cnblogs.com/qiudabai/articles/9219840.html https://www.opendns.com/about/inn ...

  3. 【hdu 6172】Array Challenge(数列、找规律)

    多校10 1002 HDU 6172 Array Challenge 题意 There's an array that is generated by following rule. \(h_0=2, ...

  4. Coding and Paper Letter(五十八)

    资源整理. 1 Coding: 1.支持TMS.WMTS标准瓦片下载,支持百度地图瓦片.高德地图瓦片.腾讯地图瓦片.天地图.ArcServer Rest瓦片.ArcServer本地缓存切片.geose ...

  5. 【java+selenium】网易云音乐刷累计听歌数

    背景应该是在去年的时候,刷知乎看到一个问题,大概是说怎么刷网易云音乐个人累计听歌数,然后有一个高赞回答,贴了一段js代码,直接在浏览器console执行就可以了.当时试了下,直接一下子刷了有好几万.悲 ...

  6. Linux内核进程

    公司数据库机器报警进程数高于1500,登进去ps命令看了一下,这么多进程并不认识,就在网上找了一些关于linux进程的资料,如下: idle 进程的pid=0,是由系统自动创建的第一个进程,也是唯一的 ...

  7. Android 开发中 SQLite 数据库的使用

    SQLite 介绍 SQLite 一个非常流行的嵌入式数据库,它支持 SQL 语言,并且只利用很少的内存就有很好的性能.此外它还是开源的,任何人都可以使用它.许多开源项目((Mozilla, PHP, ...

  8. 构建SFTP服务

    ---------------增加sftp-----------------查看openssh的版本# ssh -V使用ssh -V 命令来查看openssh的版本,版本必须大于4.8p1,低于的这个 ...

  9. Fiddler 安装配置及使用技巧

    下载最新版即可: https://www.telerik.com/fiddler pc配置: pc端上的配置较为简单,主要是记录一下遇到的一些bug以及解决方法. options>HTTPS  ...

  10. mysql5.6更改datadir数据存储目录

    环境需求: 有些数据存储场景可能需要将数据放到指定的挂载路径或目录,mysql默认存放数据路径在:/var/lib/mysql下. 测试环境: 操作步骤: 1. 查看当前存储目录 [root@mysq ...