题意

给出两个数字 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";
}
}

最新文章

  1. php实现中文转数字,实现方式很智能很php
  2. 集成SDK查看包架构指令
  3. Mybatis 实用
  4. 《Linux/Unix系统编程手册》读书笔记6
  5. BJUI 转
  6. Linux中搭建SVN服务器
  7. Excel如何进行SVN
  8. 微信小程序支付遇到的坑
  9. PHP 扩展管理
  10. rocketmq双主模式
  11. zabbix全网监控
  12. 栈长这里是生成了一个 Maven 示例项目。
  13. react-native中使用长列表
  14. [C#]SmtpClient发送邮件
  15. JS 数组位置方法 indexOf()和lastIndexOf()的理解
  16. mysql 之各种 join 之间的关系
  17. Java Web(八) MVC和三层架构
  18. UVALive 6467 Strahler Order(拓扑序列)
  19. php底层HashTable的实现
  20. 动态加载javascript增强版

热门文章

  1. mongodb更新器
  2. 在海思hisiv100nptl平台上交叉编译并安装SRS
  3. android studio中如何替换gradle以防下载卡住
  4. 第一百六十八节,jQuery,表单选择器
  5. struts.xml文件:
  6. Eclipse 透视图(Perspective)
  7. PHP中通过数组遍历找出最小值
  8. azure iothub create-device-identity样例报错: unable to find valid certification path ,及iothub-explorer Error: CERT_UNTRUSTED
  9. poj2420(模拟退火大法好)
  10. 【BZOJ2794】[Poi2012]Cloakroom 离线+背包