uva 10831 - Gerg's Cake(勒让德符号)
题目大意:给定a和p。p为素数,问说是否存在x,使得x2≡a%p
解题思路:勒让德记号,推断ap−12≡1%p
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll pow_mod (ll a, ll n, ll mod) {
ll ans = 1;
while (n) {
if (n&1)
ans = ans * a % mod;
a = a * a % mod;
n /= 2;
}
return ans;
}
int legendre (ll a, ll p) {
a %= p;
if (a == 0)
return 0;
if (pow_mod(a, (p-1)/2, p) == 1)
return 1;
else
return -1;
}
int main () {
ll a, p;
while (scanf("%lld%lld", &a, &p) == 2 && a != -1 && p != -1) {
if (legendre(a, p) < 0)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
uva 10831 - Gerg's Cake(勒让德符号)的更多相关文章
- UVA 10831 - Gerg's Cake(数论)
UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: ...
- UVA 816 - Abbott's Revenge(BFS)
UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...
- uva 11825 Hackers' Crackdown (状压dp,子集枚举)
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...
- UVA 12103 - Leonardo's Notebook(数论置换群)
UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) ...
- UVA 11774 - Doom's Day(规律)
UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / ...
- UVA The Sultan's Successors
题目例如以下: The Sultan's Successors The Sultan of Nubia has no children, so she has decided that thecou ...
- BestCoder Round #75 King's Cake 模拟&&优化 || gcd
King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...
- UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集
UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...
- uva 11178 Morley's Theorem(计算几何-点和直线)
Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states tha ...
随机推荐
- Linux scp文件复制
scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令. 1.scp命令的用处: scp在网络上不同的主机之间复制文件,它使用ssh安全协议传输 ...
- 开放源代码的微微信.NET 0.8 版公布了
微微信.NET 0.8 版公布了 A.源代码应用范围: 未认证的和经过认证的微信订阅号.微信服务号均可使用,本源代码的每个模块都提供全然的 ASP.NET C#源代码,绝对不含 ...
- finger用户名、主目录、停滞时间、登录时间
finger yum install finger 1.作用 finger用来查询一台主机上的登录账号的信息,通常会显示用户名.主目录.停滞时间.登录时间.登录Shell等信息,使用权限为 ...
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
在使用Hibernate的J2EE项目中,莫名其妙出现如上错误,既不报错,也不运行不论什么输出測试代码,更不返回结果. 经过排查,在方法里面引用的实体类和其映射文件属性个数不一致. 改动一致后,即解决 ...
- css中换行的几种方式
1.white-space:normal; 这个只针对中文有效 2.word-break:break-all; 强制换行,针对中文,数字,英文等都有效: 3.word-wrap:break-wo ...
- pygame系列_mouse鼠标事件
pygame.mouse提供了一些方法获取鼠标设备当前的状态 ''' pygame.mouse.get_pressed - get the state of the mouse buttons get ...
- VMware GSX Server 3.2.1 Build 19281免费下载
VMware GSX Server 3.2.1 Build 19281免费下载 评论2 字号:大中小 订阅 VMware官方下载: For Windows 版系统:http://download3 ...
- 使用psftp.exe
使用psftp.exe 点击打开psftp.exe,出现如下图的命令窗口.
- Android kxml解析WBXML
WAP Binary XML定义好XML片断表述出同步server地址.远程数据库名称.登录账号等等内容一.两种訪问方法: 眼下的kxml支持两种wap格式:WBXML/WML. 而有两种方法将解析 ...
- ZOJ 2334(Monkey King-左偏树第一题)
Monkey King Time Limit: 10 Seconds Memory Limit: 32768 KB Once in a forest, there lived N aggre ...