Pseudoprime numbers(POJ 3641 快速幂)
#include <cstring>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL long long
LL p,res,a;
bool judge_prime(LL k)
{
LL i;
LL u=int(sqrt(k*1.0));
for(i=;i<=u;i++)
{
if(k%i==)
return ;
}
return ;
}
int main()
{
freopen("in.txt","r",stdin);
while(scanf("%lld%lld",&p,&a))
{
if(p==&&a==)
break;
if(judge_prime(p))
{
printf("no\n");
continue;
}
res=;
LL t=p;
LL w=a;
while(p)
{
if(p&) res=(res*a)%t;
a=(a*a)%t;
p>>=;
}
if(res==w)
printf("yes\n");
else
printf("no\n");
}
}
Pseudoprime numbers(POJ 3641 快速幂)的更多相关文章
- POJ 3641 快速幂+素数
http://poj.org/problem?id=3641 练手用,结果念题不清,以为是奇偶数WA了一发 #include<iostream> #include<cstdio> ...
- poj 3641 快速幂
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...
- Mathematics:Pseudoprime numbers(POJ 3641)
强伪素数 题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers) 很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是 ...
- Raising Modulo Numbers(POJ 1995 快速幂)
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5934 Accepted: ...
- POJ 1845-Sumdiv(快速幂取模+整数唯一分解定理+约数和公式+同余模公式)
Sumdiv Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- POJ 1995 快速幂模板
http://poj.org/problem?id=1995 简单的快速幂问题 要注意num每次加过以后也要取余,否则会出问题 #include<iostream> #include< ...
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ...
- 2008 Round 1A C Numbers (矩阵快速幂)
题目描述: 请输出(3+√5)^n整数部分最后3位.如果结果不超过2位,请补足前导0. 分析: 我们最容易想到的方法肯定是直接计算这个表达式的值,但是这样的精度是不够的.朴素的算法没有办法得到答案.但 ...
- poj 1995 快速幂
题意:给出A1,…,AH,B1,…,BH以及M,求(A1^B1+A2^B2+ … +AH^BH)mod M. 思路:快速幂 实例 3^11 11=2^0+2^1+2^3 => 3^1*3 ...
随机推荐
- PHP手册应注意
1.抽象类翻译.错误.在语言参考→类与对象→抽象类一节的开头,有这样的描述"抽象类中 至少要包含一个抽象方法."(http://www.php.net/manual/zh/lang ...
- Android 设置让EditText不自动获取焦点
在EditText所在的父控件中设置如下属性: android:focusable="true" android:focusableInTouchMode="true&q ...
- 【转帖】.Net中C#的DllImport的用法
在 C# 中通过 P/Invoke 调用Win32 DLL http://msdn.microsoft.com/zh-cn/library/aa686045.aspx 大家在实际工作学习C#的时候 ...
- Linux/UNIX环境下Oracle数据库多实例开机启动脚本(转)
操作系统平台:RHEL 5Shell环境:BashOracle:10g2 功能描述:开机时自动切换到oracle用户下,启动oracle的多个实例.并记录数据库的启动情况到自定义的日志文件中. #!/ ...
- eclipse打开文件位置Open Explorer 插件
,OpenExplorer插件可以满足这个功能,可以到https://github.com/samsonw/OpenExplorer/downloads下载最新版本,将jar包放到eclipse的pl ...
- 使用git pull时,项目没有更新?
进入项目目录后,执行 git pull 命令,没有将项目更新,并提示下图: 提示:there is no tracking information for the current branch. 意思 ...
- linux网址
1. 上海爱墨电子科技有限公司 http://www.shaimo.cn/showproduct.asp?piccat_id=196&pic_id=780 2. http://lxr.free ...
- Android_Studio常用插件
Android studio常用插件,可极大简化开发,增强开发效率. 不懂安装studio插件,看参考博文:android stuido插件安装:http://blog.csdn.net/liang5 ...
- 【HDU1198】Farm Irrigation(回溯+记忆化搜索)
数据流小,深搜即可.有些暴力.看其他人的题解用二维转换成一维做的并查集很巧妙,马上去研究一下!! #include <iostream> #include <cstring> ...
- html天气预报小插件
<head></head> <body> <iframe width="225" scrolling="no" hei ...