题意

给出两个数字 P 和 A 当p 不是素数 并且 满足a^p≡a(mod p) 就输出 yes 否则 输出 no

思路

因为 数据范围较大,用快速幂

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream> using namespace std;
typedef long long LL; const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6; const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7; LL powerMod(LL x, LL n, LL m)
{
LL res = 1;
while (n > 0)
{
if (n & 1)
res = (res * x) % m;
x = (x * x ) % m;
n >>= 1;
}
return res;
} bool isPrime(int x)
{
int flag;
int n, m;
if (x <= 1)
return false;
if (x == 2 || x == 3)
return true;
if (x % 2 == 0)
return false;
else
{
m = sqrt(x) + 1;
for (n = 3; n <= m; n += 2)
{
if (x % n == 0)
{
return false;
}
}
return true;
}
} int main()
{
LL p, a;
while (cin >> p >> a && (p || a))
{
if (powerMod(a, p, p) == a && a % p == a && isPrime(p) == false)
cout << "yes\n";
else
cout << "no\n";
}
}

Kattis - pseudoprime 【快速幂】的更多相关文章

  1. POJ3641 Pseudoprime numbers(快速幂+素数判断)

    POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...

  2. GCD&&素筛&&快速幂 --A - Pseudoprime numbers

    Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). Th ...

  3. POJ 3641 Pseudoprime numbers (数论+快速幂)

    题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...

  4. 【快速幂】POJ3641 - Pseudoprime numbers

    输入a和p.如果p不是素数,则若满足ap = a (mod p)输出yes,不满足或者p为素数输出no.最简单的快速幂,啥也不说了. #include<iostream> #include ...

  5. pojPseudoprime numbers (快速幂)

    Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...

  6. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  7. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  8. hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)

    题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3.                  ...

  9. Codeforces632E Thief in a Shop(NTT + 快速幂)

    题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...

随机推荐

  1. Unix环境高级编程(一)

    Unix基础知识1.引言2.Unix体系结构3.登陆4.文件和目录5.输入和输出6.程序和进程7.出错和处理8.用户标示9.信号10.时间值11.系统调用和库函数12.小结

  2. 【转载】利用MAVEN打包时,如何包含更多的资源文件

    首先,来看下MAVENx项目标准的目录结构: 一般情况下,我们用到的资源文件(各种xml,properites,xsd文件等)都放在src/main/resources下面,利用maven打包时,ma ...

  3. poj 2942 Knights of the Round Table(无向图的双连通分量+二分图判定)

    #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #includ ...

  4. BZOJ 1798 AHOI2009 Seq 维护序列 线段树

    题目大意:维护一个序列,提供三种操作: 1.将区间中每个点的权值乘上一个数 2.将区间中每个点的权值加上一个数 3.求一段区间的和对p取模的值 2631的超^n级弱化版.写2631之前能够拿这个练练手 ...

  5. Google Careers 程序员必修课

    quote from : https://www.google.com/about/careers/students/guide-to-technical-development.html Techn ...

  6. for循环的执行循序

    先上一段代码,大家说出此方法的执行结果: public class Print{ static boolean out(char c){ System.out.println(c); return t ...

  7. 深入了解UIAutomation 的API

    有关UiAUiAutomation的API对象的文件名称. 1.UIAutomation中的对象都是以UIA#####开头的出现的.eg:UIAButton 2.有关Logger对象负责日志的输出 U ...

  8. GUN C中的流

    当我们要对文件(在Linux环境中一切皆文件,包括硬件设备.资源等)进行操作(读.写.读写)时,必须连接文件或形成通信管道.这个过程称为打开文件.打开文件后可以进行读.写.读写操作. 打开的文件可以称 ...

  9. 学习boost::asio一些小例子

    # #include <boost/asio.hpp> #include <boost/thread.hpp> #include <iostream> void h ...

  10. Linux 进程间通信(二)(网络IPC:套接字)

    socket描述符 套接字是通信端点的抽象,创建一个套接字使用如下函数: #include <sys/socket.h> int socket(int domain, int type, ...