#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 快速幂)的更多相关文章

  1. POJ 3641 快速幂+素数

    http://poj.org/problem?id=3641 练手用,结果念题不清,以为是奇偶数WA了一发 #include<iostream> #include<cstdio> ...

  2. poj 3641 快速幂

    Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...

  3. Mathematics:Pseudoprime numbers(POJ 3641)

     强伪素数 题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers) 很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是 ...

  4. Raising Modulo Numbers(POJ 1995 快速幂)

    Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5934   Accepted: ...

  5. POJ 1845-Sumdiv(快速幂取模+整数唯一分解定理+约数和公式+同余模公式)

    Sumdiv Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  6. POJ 1995 快速幂模板

    http://poj.org/problem?id=1995 简单的快速幂问题 要注意num每次加过以后也要取余,否则会出问题 #include<iostream> #include< ...

  7. UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

      Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people e ...

  8. 2008 Round 1A C Numbers (矩阵快速幂)

    题目描述: 请输出(3+√5)^n整数部分最后3位.如果结果不超过2位,请补足前导0. 分析: 我们最容易想到的方法肯定是直接计算这个表达式的值,但是这样的精度是不够的.朴素的算法没有办法得到答案.但 ...

  9. 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 ...

随机推荐

  1. Unity3D 定时发射子弹

    using UnityEngine; public class example : MonoBehaviour { public GameObject projectilePrefab; public ...

  2. Flume Channel

    http://blog.csdn.net/john_f_lau/article/details/20913831 http://dev.cmcm.com/archives/194

  3. Tomcat JVM

    https://www.mulesoft.com/tcat/tomcat-jvm https://www.mulesoft.com/tcat/tomcat-catalina https://www.m ...

  4. LeetCode_Reverse Integer

    Reverse digits of an integer. Example1: x = , Example2: x = -, class Solution { public: int reverse( ...

  5. PowerShell_零基础自学课程_2_Powershell与Cmd以及Unix/Linux Shell

    上篇文章我说道,windows为了改变用户对其console界面的诟病,于是就从windows   vista开始,计划要改变这种局面,于是就有 了Powershell的出现. 1.兼容shell命令 ...

  6. 【转】Android下编译jni库的二种方法(含示例)

    原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd01011384.html 总结如下:两种方法是:1)使用Android源码中的Make系统2)使用NDK(从N ...

  7. unix c 01

    gcc编译器(代码的 预处理/汇编/编译/连接) C程序员一般写程序会定义 .c和.h两种文件 .c文件(源文件)中一般放代码的实现,.h文件(头文件)中放 各种声明和定义.   gcc -E __. ...

  8. ASP.NET MVC URL重写与优化(进阶篇)-继承RouteBase

    原文地址:http://www.51csharp.com/MVC/882.html   ASP.NET MVC URL重写与优化(进阶篇)-继承RouteBase玩转URL 引言-- 在初级篇中,我们 ...

  9. 【剑指offer】面试题31:连续子数组的最大和

    题目: 在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量中包含负数,是否应该包含某个负数,并期望旁边的正数会弥补它呢?例如:{6,-3,-2, ...

  10. <转载>僵尸进程

    转载http://www.cnblogs.com/scrat/archive/2012/06/25/2560904.html 什么是僵尸进程 僵尸进程是指它的父进程已经退出(父进程没有等待(调用wai ...