-->Carmichael Numbers

 Descriptions:

题目很长,基本没用,大致题意如下

给定一个数n,n是合数且对于任意的1 < a < n都有a的n次方模n等于a,这个数就是Carmichael Number.

输出The number n is a Carmichael number.

n是素数

输出

n is normal.

Input

多组输入,第一行给一个n (2 < n < 65000) 。n = 0 表示输入结束并不需要处理

Output

对每组输入,输出它是不是卡迈克尔数,参考样例。

Sample Input

1729
17
561
1109
431
0

Sample Output

The number 1729 is a Carmichael number.
17 is normal.
The number 561 is a Carmichael number.
1109 is normal.
431 is normal.
题目链接
 
可以先判定n是否为合数,是就接着判断。
由于i的n次方的值可能很大,因此次题可以采用快速幂取余,由于数值范围可能很大,因此可采用long long 类型。
 
AC代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 65000+10
using namespace std;
ll n;
ll mod;
int isprime[Maxn];//素数表
void eratos(int x)//求素数表,true为素数
{
for(int i=; i<=x; ++i)
isprime[i]=true;
isprime[]=isprime[]=false;
for(int i=; i<=x; ++i)
{
if(isprime[i])
{
int j=i+i;
while(j<=x)
{
isprime[j]=false;
j+=i;
}
}
}
}
ll qpow(ll a, ll n)//计算a^n % mod 快速幂
{
ll re = ;
while(n)
{
if(n & )//判断n的最后一位是否为1
re = (re * a) % mod;
n >>= ;//舍去n的最后一位
a = (a * a) % mod;//将a平方
}
return re % mod;
}
int main()
{
eratos(Maxn-);
while(cin>>n,n)
{
if(isprime[n])//是素数
cout << n << " is normal." << endl;
else//不是素数
{
int f=;
for(int i=; i<n; i++)//判断
{
mod=n;
ll t=qpow(i,n);
if(t!=i)
{
f=;
cout << n << " is normal." << endl;
break;
}
}
if(f)
cout << "The number " << n <<
" is a Carmichael number." << endl;
}
}
}

【UVA - 10006 】Carmichael Numbers (快速幂+素数筛法)的更多相关文章

  1. Uva 10006 Carmichael Numbers (快速幂)

    题意:给你一个数,让你判断是否是非素数,同时a^n%n==a (其中 a 的范围为 2~n-1) 思路:先判断是不是非素数,然后利用快速幂对每个a进行判断 代码: #include <iostr ...

  2. UVa 10006 - Carmichael Numbers

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

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

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

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

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

  5. poj 3641 Pseudoprime numbers 快速幂+素数判定 模板题

    Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7954 Accepted: 3305 D ...

  6. pojPseudoprime numbers (快速幂)

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

  7. POJ1995 Raising Modulo Numbers(快速幂)

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

  8. POJ 1995:Raising Modulo Numbers 快速幂

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

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

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

随机推荐

  1. 解决C++项目使用sqlite中文乱码问题

    我参考的是这篇文章:https://www.2cto.com/database/201411/354891.html 理论是:sqlite使用的是UTF-8,C++中用的字符串是ascii或unico ...

  2. Hadoop中一些重要概念简要总结

    Hadoop是一个利用大规模计算机集群,可处理大量数据的分布式并行框架. Hadoop 官网 Hadoop的核心设计包括HDFS和MapReduce. HDFS HDFS(Hadoop Distrib ...

  3. NFS服务设置

    1.安装NFS服务sudo apt-get install nfs-common nfs-kernel-server 2.配置NFS服务首先需要手动编辑/etc/exports配置文件 权限参数说明如 ...

  4. Linux 桌面玩家指南:19. 深入理解 JavaScript,及其开发调试工具

    特别说明:要在我的随笔后写评论的小伙伴们请注意了,我的博客开启了 MathJax 数学公式支持,MathJax 使用$标记数学公式的开始和结束.如果某条评论中出现了两个$,MathJax 会将两个$之 ...

  5. QT5---应用程序发布(使用windeployqt和NSIS)

      采用动态编译的方式发布程序,即release版本. 找齐动态依赖库(.dll) 方法一   用Dependency Walker这个工具去找少了那些dll,不过这个工具也不怎么靠谱,一个比较靠谱但 ...

  6. WCF学习--我的第一个WCF例子

    Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口. 通信双方的沟通方式,由合约来订定.通信双方所 ...

  7. MySQL之SQL优化详解(三)

    目录 MySQL 之SQL优化详解(三) 1. 索引优化 2. 剖析报告:Show Profile MySQL 之SQL优化详解(三) 1. 索引优化 一旦建立索引,select 查询语句的where ...

  8. Appium+python自动化(十二)- Android UIAutomator终极定位凶“胸”器(七)(超详解)

    简介 乍眼一看,小伙伴们觉得这部分其实在异性兄弟那里就做过介绍和分享了,其实不然,上次介绍和分享的大哥是uiautomatorviewer,是一款定位工具.今天介绍的是一个java库,提供执行自动化测 ...

  9. Java内存区域(运行时数据区域)和内存模型(JMM)

    Java 内存区域和内存模型是不一样的东西,内存区域是指 Jvm 运行时将数据分区域存储,强调对内存空间的划分. 而内存模型(Java Memory Model,简称 JMM )是定义了线程和主内存之 ...

  10. CentOS 7使用Elasticsearch

    安装ElasticSearch 下载依赖 Elasticsearch依赖jdk, 在官网下载jdk压缩包, 或者直接安装. 下载压缩包, 解压tar -xzvf jdk-8u181-linux-x64 ...