题意

给出两个数字 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. wp8页面导向

    一般打开的是MainPage.xaml需要打开另一个页面的时候,用NavigationService.Navigate(uri);当然uri要配置是相对路径还是绝对路径Uri uri = new Ur ...

  2. pycharm2018.1.4激活破解方法与汉化包-2018年6月19日

    记录下来备用,顺便分享给大家,有能力的还是希望能够支持正版!支持正版!支持正版! 方法1:激活服务器,最简单快速(截止2018年6月19日可用) 在激活Jetbrains旗下任意产品的时候选择激活服务 ...

  3. php5.4n 长链接 bug

    运行5.2的部分程序会有中文无法显示的问题 恢复到5.2后中文显示正常

  4. ChemDraw破解版真的不大好用

    一直以来都有很多的用户朋友在网上找ChemDraw破解版使用,但是现在厂商清理的厉害,还有国家对知识产权的保护越来越严格,破解版ChemDraw越来越难找了.大家与其花那么多的时候找破解版的,不如买个 ...

  5. zmq重点

    The zmq_msg_send(3) method does not actually send the message to the socket connection(s). It queues ...

  6. UILabel标签文字过长时的显示方式

    lineBreakMode:设置标签文字过长时的显示方式. label.lineBreakMode = NSLineBreakByCharWrapping; //以字符为显示单位显示,后面部分省略不显 ...

  7. centos7下挂载U盘和移动硬盘

    挂载U盘 1.使用fdisk -l命令查看磁盘情况 [root@localhost ~]# fdisk -l 磁盘 /dev/sda:1000.2 GB, 1000204886016 字节,19535 ...

  8. NoSQL-MongoDB with python

    前言: MongoDB,文档存储型数据库(document store).NoSQL数据库中,它独占鳌头,碾压其他的NoSQL数据库. 使用C++开发的,性能仅次C.与redis一样,开源.高扩展.高 ...

  9. Linux - Ubuntu Server基础

    Ubuntu Server:部署环境,用来部署项目的server系统. XShell:用来连接linux的工具.web项目要部署到远程服务器上,所以需要XShell来连接远程服务器. pycharm: ...

  10. hdu4266(三维凸包模板题)

    /*给出三维空间中的n个顶点,求解由这n个顶点构成的凸包表面的多边形个数. 增量法求解:首先任选4个点形成的一个四面体,然后每次新加一个点,分两种情况: 1> 在凸包内,则可以跳过 2> ...