题意:给你一个数,让你判断是否是非素数,同时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. groovy hello world

    安装方法见官方文档http://groovy.codehaus.org/Installing+Groovy 用新一个文件HelloWorld.groovy,以utf8的编码保存,内容为: printl ...

  2. 关于C语言中变量类型转换

    今天在工作中遇到一个问题,而在解决问题的过程中,发现一段关于int 型变量(a)和char型(b)变量间类型转换的代码存在问题:一个值为255的int型变量a,强制类型转换并赋值给char型变量b后, ...

  3. Tinyshell: 一个简易的shell命令解释器

    这是自己最近学习Linux系统编程之后写的一个练手的小程序,能很好地复习系统编程中的进程管理.信号.管道.文件等内容. 通过回顾写的过程中遇到的问题的形式记录程序的关键点,最后给出完整程序代码. 0. ...

  4. 一张图看懂 JS 的事件机制

    一.为什么 JavaScript 单线程 假定JavaScript同时有两个线程,一个线程在某个DOM节点上添加内容,另一个线程删除了这个节点,这时浏览器应该以哪个线程为准? 为了避免复杂性, JS ...

  5. MongoDB【第二篇】集群搭建

    第一步:准备 1.安装包 mongodb-linux-x86_64-rhel70-3.4.2.tgz 2. 架构: 本文为 1-primary.1-secondary.1-arbiter 的 mong ...

  6. ios 相机调用之读取相册

    UIIamgePickerControllerr可以从照片库中读取一张图片到咱们应用程序中来   步骤:   //创建图片判断图片库是否可以使用   if([UIImagePickerControll ...

  7. Asp.net缓存技术(HttpRuntime.Cache)

    一.缓存: 5个等级的缓存 1级是网络级缓存,缓存在浏览器,CDN以及代理服务器中   (举个例子:每个帮助页面都进行了缓存,访问一个页面的代码非常简单) 2级是由.net框架 HttpRuntime ...

  8. ajax详细讲解和封装包括HTTP状态码

    AJAX(异步的JavaScript和XML,用异步的形式去操作xml) 主要的作用:数据交互   好处:               1.节省用户的操作时间               2.提高用户 ...

  9. 3391: [Usaco2004 Dec]Tree Cutting网络破坏

    3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 76  Solved: 59[ ...

  10. Spark Core_资源调度与任务调度详述

    转载请标明出处http://www.cnblogs.com/haozhengfei/p/0593214ae0a5395d1411395169eaabfa.html Spark Core_资源调度与任务 ...