题意:给你一个数,让你判断是否是非素数,同时a^n%n==a (其中 a 的范围为 2~n-1)

思路:先判断是不是非素数,然后利用快速幂对每个a进行判断

代码:

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std; bool isprime(ll num)
{
if(num==) return false;
for(int i=;i<=sqrt(num);i++)
{
if(num%i==)
{
return false;
}
}
return true;
} ll qmod(ll a,ll b)
{
ll mod=b;
ll ans=;
while(b)
{
if(b%)
{
ans=(ans*a)%mod;
}
b=b/;
a=(a*a)%mod;
}
return ans;
} int main()
{
ll n;
while(cin>>n&&n)
{
if(isprime(n)==true)
{
cout<<n<<" is normal."<<endl;
continue;
}
int flag=;
for(int i=;i<=n-;i++)
{
if(i!=qmod(i,n))
{
flag=;
break;
}
}
if(flag)
{
printf("The number %d is a Carmichael number.\n",n);
}
else
{
cout<<n<<" is normal."<<endl;
}
}
return ;
}

Uva 10006 Carmichael Numbers (快速幂)的更多相关文章

  1. UVa 10006 - Carmichael Numbers

    UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...

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

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

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

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

  4. pojPseudoprime numbers (快速幂)

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

  5. POJ1995 Raising Modulo Numbers(快速幂)

    POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...

  6. POJ 1995:Raising Modulo Numbers 快速幂

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

  7. UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...

  8. ZOJ2150 Raising Modulo Numbers 快速幂

    ZOJ2150 快速幂,但是用递归式的好像会栈溢出. #include<cstdio> #include<cstdlib> #include<iostream> # ...

  9. UVa 10870 Recurrences (矩阵快速幂)

    题意:给定 d , n , m (1<=d<=15,1<=n<=2^31-1,1<=m<=46340).a1 , a2 ..... ad.f(1), f(2) .. ...

随机推荐

  1. 20150817---成长日记1---DelayQueue&&Delayed&&Other

    今天第一次接触DelayQueue,源于项目中的话单解析入库的拆分线程中引入,首先简单了解一下DelayQueue: DelayQueue是一个无界阻塞队列,只有在延迟期满时才能从中提取元素.该队列的 ...

  2. Nginx+Python+uwsgi+Django的web开发环境安装及配置

    Nginx+Python+uwsgi+Django的web开发环境安装及配置 nginx安装 nginx的安装这里就略过了... python安装 通常系统已经自带了,这里也略过 uwsgi安装 官网 ...

  3. android学习4——View的长宽问题

    画形状的时间经常会用到点的坐标,这时原点O的位置就非常重要.在像素为1280*720的设备上画一条直线.代码如下所示: import android.app.Activity; import andr ...

  4. 极光推送-Java后台实现方式一:Http API

    Java后台实现极光推送有两种方式,一种是使用极光推送官方提供的推送请求API:https://api.jpush.cn/v3/push,另一种则是使用官方提供的第三方Java APIjar包,这里先 ...

  5. JAVA 在程序中存储和修改信息

    1.语句和表达式 计算机程序是一组告诉计算机什么的指令,每一个指令称为语句. 2.指定变量类型 变量名.变量存储的信息类型 整型int(-2.14*109~2.14*109).浮点型float(38位 ...

  6. C# Redis之ServiceStack

    前面几篇博客基本把redis基本操作学习了下,但一些高级应用并没有写进博客,例如持久化.虚拟内存等,像这些主要是通过配置文件来解决的,运维方向可能更侧重一些,对于开发者来说,可能就想知道怎么用C#来和 ...

  7. 《你不知道的JavaScript》整理(五)——值与原生函数

    一.值 1)数字 JavaScript只有一种数值类型:number(数字),包括"整数"和带小数的十进制数. //数字的语法 a.toExponential(); // &quo ...

  8. 自定义 Layout布局 UICollectionViewLayout

    from:   http://www.tuicool.com/articles/vuyIriN 当我们使用系统自带的UICollectionViewFlowLayout无法实现我们的布局时,我们就可以 ...

  9. struts2知识点复习

    一. MVC Model 1:将所有的程序代码,都写到JSP页面中. Model 2:JSP(流程控制.数据显示) + JavaBean 改进的Model2:Servlet(流程控制) + Jsp(数 ...

  10. TypeScript设计模式之中介者、观察者

    看看用TypeScript怎样实现常见的设计模式,顺便复习一下. 学模式最重要的不是记UML,而是知道什么模式可以解决什么样的问题,在做项目时碰到问题可以想到用哪个模式可以解决,UML忘了可以查,思想 ...