题意

给出两个数字 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. Tomcat启动报错:SERVER: Error ListenerStart 排查过程记录

    报错的Tomcat截图:   要排查此问题,首先需要调整tomcat的日志级别,调整成通过log4j来记录日志的方式,具体的调整方式: http://tomcat.apache.org/tomcat- ...

  2. python 开发技巧(3)-- 连接mysql 出现错误 ModuleNotFoundError: No module named 'MySQLdb'

    python3中使用mysql报错ModuleNotFoundError: No module named 'MySQLdb' 原因是:在python2.x中用mysqldb,但是在python3.x ...

  3. 单点登录SSO简介

    一.什么是单点登录SSO(Single Sign-On) SSO是一种统一认证和授权机制,指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用 ...

  4. OC 内存管理-02 ARC 内存管理

    ARC 管理 概念: ARC简单,不用程序员在去管理内存 1.强指针 Strong[] :只要有强指针指向一个对象,那么系统就不会回收该对象 2.弱指针 weak :只要没有强指针指向对象,系统立即回 ...

  5. tomcat设置web根目录

  6. Redis快速入门及实现

    redis的概念 (1)Redis的优点 以下是Redis的一些优点. 异常快 - Redis非常快,每秒可执行大约110000次的设置(SET)操作,每秒大约可执行81000次的读取/获取(GET) ...

  7. NGINX快速部署

    NGINX快速部署 #!/bin/bash ############################################################################## ...

  8. 页面加载,使用ajax查询某个类别,并且给它们添加(拼接)连接

    直接上代码 $(function(){ var a = ''; $.get("productType1_findAll.action",function(data){ consol ...

  9. sql 分组后查询最大所有列信息

    CREATE TABLE students (course varchar(10), stu_name varchar(10), city varchar(10), score int ) inser ...

  10. SQL Server 阻止了对组件“Ad Hoc Distributed Queries”的 STATEMENT“OpenRowset/OpenDatasource”的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用“Ad Hoc Distributed Queries”。有关启用“Ad Hoc Distributed Queries”

    1.开启Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句: exec sp_configure reconfigure exec sp_configure r ...