Uva 10006 Carmichael Numbers (快速幂)
题意:给你一个数,让你判断是否是非素数,同时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 (快速幂)的更多相关文章
- UVa 10006 - Carmichael Numbers
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ...
- POJ3641 Pseudoprime numbers(快速幂+素数判断)
POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...
- pojPseudoprime numbers (快速幂)
Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...
- POJ1995 Raising Modulo Numbers(快速幂)
POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...
- POJ 1995:Raising Modulo Numbers 快速幂
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5532 Accepted: ...
- UVA 11609 Teams 组合数学+快速幂
In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...
- ZOJ2150 Raising Modulo Numbers 快速幂
ZOJ2150 快速幂,但是用递归式的好像会栈溢出. #include<cstdio> #include<cstdlib> #include<iostream> # ...
- UVa 10870 Recurrences (矩阵快速幂)
题意:给定 d , n , m (1<=d<=15,1<=n<=2^31-1,1<=m<=46340).a1 , a2 ..... ad.f(1), f(2) .. ...
随机推荐
- Spring Mvc + Easyui中根据查询结果导出文件
项目是典型的SpringMvc + Easyui,需求是前台页面根据查询条件导出生成CSV文件. 基本流程是:前台页面通过表单提交的方式,请求后台,后台接受到查询参数,根据查询参数查询到数据集合,最后 ...
- STM32F4的FPU单元讲解
搞STM32F407单片机的时候 看见的关于STM32F4系列的FPU 单元讲解 比较精彩的博客 于是特意转载 和大家分享 转自:http://blog.renren.com/blog/256814 ...
- iOS runtime的应用实例
一直想弄明白runtime是怎么回事,因为面试的时候这是一道必备问题,但是平时用的机会真的少之又少,我一度以为runtime只是用来装13的利器,没什么卵用.但是随着学习的增多,发现runtime ...
- 解决新建maven项目速度慢的问题
问题描述 通过idea新建maven项目,参数设置好后,idea自动构建maven项目时,速度很慢. 参数设置如图: 执行时间如下图: Total time为8:49,花了将近十分钟时间. 连续尝试了 ...
- 信号处理——Hilbert变换及谱分析
作者:桂. 时间:2017-03-03 23:57:29 链接:http://www.cnblogs.com/xingshansi/articles/6498913.html 声明:转载请注明出处, ...
- 未来工厂——电器行业ERP案例
江苏科兴电器有限公司位于全国著名的“银杏之乡”泰兴市南首,主要生产35kV及以下电流.电压互感器等系列产品.产品多次经国家及省市技术监督部门抽检合格,广泛应用于国家重点工程.“COSINE”商标荣获泰 ...
- Android中使用findViewByMe提升组件查找效率
1.引出 安卓初学者一般在写android Activity的时候总是会在onCreate方法中加上setContentView方法来加载layout,通过findViewById来实现控件的绑定,刚 ...
- 棋盘覆盖(一) ACM
棋盘覆盖 描述 在一个2k×2k(1<=k<=100)的棋盘中恰有一方格被覆盖,如图1(k=2时),现用一缺角的2×2方格(图2为其中缺右下角的一个),去覆盖2k×2k未被覆盖过的方格,求 ...
- 关于 jquery html 动态添加的元素绑定事件——On()
Ajax动态生成的数据,动作绑定需要重新执行 $(document).on('click','.btn1',function(){}); 替换: $('btn1').on('click') = fun ...
- 多线程爬坑之路-ThreadLocal源码及原理的深入分析
ThreadLocal<T>类:以空间换时间提供一种多线程更快捷访问变量的方式.这种方式不存在竞争,所以也不存在并发的安全性问题. This class provides thread-l ...