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 ...
随机推荐
- Java程序猿笔试面试之String1
1.怎样实现字符串的反转比如:"how are you"--->"you are how" public class InverseString { pu ...
- wp天气预报
ak url http://developer.baidu.com/map/index.php?title=car 后台cs using System; using System.Collectio ...
- 阿里云server(ECS)优惠券领取
CoderMan的博客也是放置在阿里云的ECS上.速度绝对是刚刚的,大家打开的速度肯定不会慢. 有些同志们至今可能还在用虚拟主机吧,其实阿里云server真心不贵,有俩种计费方式:各自是按月计费和按流 ...
- 安装pygame
pygame的安装 我们首先要去到:http://www.pygame.org/download.shtml 下载我们所需要的软件包: 我选择的是:pygame-1.9.2a0.win32-py3.2 ...
- 在iOS7中改动状态栏字体的颜色
状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarStyleLightContent 一.在info.plist中,将View contro ...
- C语言 - printf的占位符(%) 异常
printf的占位符(%) 异常 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26719135 C语言中, 使用%代表占位符的意 ...
- android com.handmark.pulltorefresh 使用技巧
近期使用android com.handmark.pulltorefresh 遇到一些小问题.如今总结一些: 集体使用教程见: http://blog.csdn.net/harvic880925/ar ...
- windows phone 使用相机并获取图片(3)
原文:windows phone 使用相机并获取图片(3) 使用相机需要引用如下命名空间 " Margin="12,10,12,0" ></Image> ...
- CC2530 外部中断 提醒
#include "ioCC2530.h" #define uchar unsigned char #define led1 P1_0 #define led2 P1_ ...
- Java 执行四则运算
四种基本的操作原理是将被转换成后缀缀表达式表达.然后计算. 转换思路和原则.可以参考将中缀表达式转化为后缀表达式 import java.math.BigDecimal; import java.ut ...