Kattis - pseudoprime 【快速幂】
2024-10-21 18:30:34
题意
给出两个数字 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";
}
}
最新文章
- php实现中文转数字,实现方式很智能很php
- 集成SDK查看包架构指令
- Mybatis 实用
- 《Linux/Unix系统编程手册》读书笔记6
- BJUI 转
- Linux中搭建SVN服务器
- Excel如何进行SVN
- 微信小程序支付遇到的坑
- PHP 扩展管理
- rocketmq双主模式
- zabbix全网监控
- 栈长这里是生成了一个 Maven 示例项目。
- react-native中使用长列表
- [C#]SmtpClient发送邮件
- JS 数组位置方法 indexOf()和lastIndexOf()的理解
- mysql 之各种 join 之间的关系
- Java Web(八) MVC和三层架构
- UVALive 6467 Strahler Order(拓扑序列)
- php底层HashTable的实现
- 动态加载javascript增强版
热门文章
- mongodb更新器
- 在海思hisiv100nptl平台上交叉编译并安装SRS
- android studio中如何替换gradle以防下载卡住
- 第一百六十八节,jQuery,表单选择器
- struts.xml文件:
- Eclipse 透视图(Perspective)
- PHP中通过数组遍历找出最小值
- azure iothub create-device-identity样例报错: unable to find valid certification path ,及iothub-explorer Error: CERT_UNTRUSTED
- poj2420(模拟退火大法好)
- 【BZOJ2794】[Poi2012]Cloakroom 离线+背包