POJ 3641 快速幂+素数
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 快速幂+素数的更多相关文章
- Pseudoprime numbers(POJ 3641 快速幂)
#include <cstring> #include <cstdio> #include <iostream> #include <cmath> #i ...
- poj 3641 快速幂
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...
- 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< ...
- POJ3641 Pseudoprime numbers(快速幂+素数判断)
POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...
- 【UVA - 10006 】Carmichael Numbers (快速幂+素数筛法)
-->Carmichael Numbers Descriptions: 题目很长,基本没用,大致题意如下 给定一个数n,n是合数且对于任意的1 < a < n都有a的n次方模n等于 ...
- Raising Modulo Numbers(POJ 1995 快速幂)
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5934 Accepted: ...
- 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 ...
- POJ 3613 快速幂+Floyd变形(求限制k条路径的最短路)
题意: 给你一个无向图,然后给了一个起点s和终点e,然后问从s到e的最短路是多少,中途有一个限制,那就是必须走k条边,路径可以反复走. 思路: 感觉很赞的一个题目,据说证明是什 ...
随机推荐
- Visual Studio的调试技巧
Visual Studio的调试技巧 [原文地址] Debugging Tips with Visual Studio 2010 [原文发表日期] 2010/8/19 10:48 AM 这是我写的关于 ...
- ansible加密命令
ansible-vault用于配置文件加密,如编写的playbook配置文件中包含敏感信息,不希望其他人随意查看,ansible-valut可加密/解密这个配置文件,刚试了下也可以加密txt文档,猜想 ...
- AOP PostSharp
using System; using System.Collections.Generic; using System.Linq; using System.Text; using PostShar ...
- OC-id、构造方法
id 简介 万能指针,能指向任何OC对象,相当于NSObject * id类型的定义 typedef struct objc_object { Class isa; } *id; 使用 // 注意:i ...
- 浅谈JavaScript中的Function引用类型
引言 在JavaScript中最有意思的就是函数了,这一切的根源在于函数实际上是一个对象.每一个函数都是Function类型的实例,而且都和其他引用类型的实例一样具有属性和方法.函数作为一个对象,因此 ...
- Flex调用java webservice
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- Spring入门_02_属性注入
Spring 的set方法(属性)注入 UserAction类中设置属性和get.set方法.(实际上只需要set方法) private List list = null; private Set s ...
- java编程中Properties类的具体作用和使用
如果不熟悉 java.util.Properties类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的.(如清单 1 所示).最近更新的java.util.Properti ...
- for while (list each)的用法
each是返回数组 指针当前指向的 元素的 索引和值: 索引有四个值: 0, 1, key, value. 0和key是一样的, 1和value是一样的 但是each只是将数组指针 向前移动 一步, ...
- ExtJS -- Grid 文本居中显示
Reference: http://stackoverflow.com/questions/6561120/extjs-4-apply-defaults-to-all-columns-in-a-gri ...