http://poj.org/problem?id=3641

练手用,结果念题不清,以为是奇偶数WA了一发

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
bool judge_prime(ll k)
{
ll i;
ll u=int(sqrt(k*1.0));
for(i=;i<=u;i++)
{
if(k%i==)
return ;
}
return ;
}
ll mod_pow(ll x,ll n,ll mod)
{
ll res=;
while(n>)
{
if(n&) res=res*x%mod;
x=x*x%mod;
n>>=;
}
return res;
}
int main()
{
ll num=,a,p;
while(~scanf("%lld %lld",&p,&a))
{
if(p==&&a==) {num=;}
else{
if(judge_prime(p)) cout<<"no"<<endl;
else{
num=mod_pow(a,p,p);
if(num==a) cout<<"yes"<<endl;
else cout<<"no"<<endl;}}
}
return ;
}

POJ 3641 快速幂+素数的更多相关文章

  1. Pseudoprime numbers(POJ 3641 快速幂)

    #include <cstring> #include <cstdio> #include <iostream> #include <cmath> #i ...

  2. poj 3641 快速幂

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

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

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

  4. POJ 1995 快速幂模板

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

  5. POJ3641 Pseudoprime numbers(快速幂+素数判断)

    POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...

  6. 【UVA - 10006 】Carmichael Numbers (快速幂+素数筛法)

    -->Carmichael Numbers  Descriptions: 题目很长,基本没用,大致题意如下 给定一个数n,n是合数且对于任意的1 < a < n都有a的n次方模n等于 ...

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

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

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

  9. POJ 3613 快速幂+Floyd变形(求限制k条路径的最短路)

    题意:       给你一个无向图,然后给了一个起点s和终点e,然后问从s到e的最短路是多少,中途有一个限制,那就是必须走k条边,路径可以反复走. 思路:       感觉很赞的一个题目,据说证明是什 ...

随机推荐

  1. lua 元表

    Set = {} Set.mt = {} function Set.new(t) local set = {} setmetatable(set, Set.mt) for _, l in ipairs ...

  2. magelinux notes

    [root@centos01 01]# cd ~jack #进入指定用户的家目录[root@centos01 jack]# cd - #切回上一次目录[root@centos01 home]# cd ...

  3. 对象Clone

    //================================================= // File Name : Clone_demo //-------------------- ...

  4. Java 组播

    MulticastSocketServer.java package cn.edu.buaa.multicast; import java.io.IOException; import java.ne ...

  5. 【OpenCV】边缘检测:Sobel、拉普拉斯算子

    推荐博文,博客.写得很好,给个赞. Reference Link : http://blog.csdn.net/xiaowei_cqu/article/details/7829481 一阶导数法:梯度 ...

  6. .net 应用迁移到Mono 工具 (Moma)

    Mono Migration Analyzer (Moma) 是一个用于开发者使用的MS .net下开发的应用程序迁移到Mono平台的不兼容性检测工具.工具通过分析.dll或者.exe程序集的代码是否 ...

  7. Python-面向对象编程(二)

    面向对象进阶篇: 初级篇中我们介绍了面向对象基本知识: 1.面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 2.介绍了类中的对象.方法和属性及类中内置的方法 3.类 是一个模板 ...

  8. Mysql函数:Last_insert_id()语法讲解

    Mysql函数可以实现许多我们需要的功能,下面介绍的Mysql函数Last_insert_id()就是其中之一,希望对您学习Mysql函数能有所帮助. 自动返回最后一个INSERT或 UPDATE 查 ...

  9. 只有文本编辑器才是王道, 什么ide都是evil的浮云, 看看linus linux的内核开发工具vim emacs

    只有文本编辑器才是王道, 什么ide都是evil的浮云, 看看linus linux的内核开发工具vim emacs [ide is evil] (http://i.cnblogs.com/EditP ...

  10. HTML5+学习笔记1-------边看代码边研究中

    document.addEventListener('touchstart',function(){ return false; },true); touchstart当手指触摸屏幕时候触发,即使已经 ...