UVA - 10006 - Carmichael Numbers (快速幂+素数判断)
来源:互联网 发布:扇贝背单词软件 编辑:程序博客网 时间:2024/05/02 02:12
题目传送:UVA - 10006
思路:就是快速幂暴力过去就行了,然后要注意点细节,就是快速幂的时候会爆int,然后就是先判断是否为素数,是素数就直接输出结果is normal,不然会超时
AC代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#include <deque>#include <cctype>#define LL long long#define INF 0x7fffffffusing namespace std;int n;int is_prime(int x) {if(x == 1) return 0;if(x == 2 || x == 3) return 1;for(int i = 2; i <= sqrt(x); i ++) {if(x % i == 0) return 0;}return 1;}int kmod(int x, int mod) {LL ret = 1;int tt = x;int t = mod;while(t) {if(t & 1) ret = (ret * x) % mod;x = ((LL)x * x) % mod;//这里会爆int t >>= 1;}if(ret == tt) return 0;else return 1; }int judge(int x) {for(int i = 2; i < n; i++) {if(kmod(i, n)) return 0;}return 1;}int main() {while(scanf("%d", &n) != EOF) {if(n == 0) break;if(!is_prime(n) && judge(n)) {//判断素数放前面,自以为没多大影响,结果TLE了一下 printf("The number %d is a Carmichael number.\n", n);}else {printf("%d is normal.\n", n);}}return 0;}
0 0
- UVA - 10006 - Carmichael Numbers (快速幂+素数判断)
- UVA 10006 - Carmichael Numbers (快速幂+筛素数)
- uva 10006 Carmichael Numbers(快速幂+素数)
- UVA - 10006 Carmichael Numbers(素数筛+快速幂)
- Carmichael Numbers - UVa 10006 素数判断
- Uva 10006 - Carmichael Numbers【素数+快速幂取模】
- uva 10006 Carmichael Numbers(快速幂)
- Uva 10006-Carmichael Numbers(快速幂)
- Uva 10006 Carmichael Numbers (快速幂)
- UVA 10006 Carmichael Numbers(快速幂)
- Uva 10006 Carmichael Numbers(数论、快速幂、素数筛法)
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
- UVa 10006 Carmichael Numbers 【快速幂+素数打表(埃氏筛法)】
- Uva 10006 Carmichael Numbers 快速幂
- UVA 10006 - Carmichael Numbers 快速幂
- UVa 10006 Carmichael Numbers (快速幂运算)
- UVA 10006 - Carmichael Numbers(快速幂取模)
- 彻底解决 error: Unable to find vcvarsall.bat
- LaTeX入门资料
- python 的日志logging模块学习
- poj 2752 KMP的next数组应用(prefix-suffix string)
- Tomcate启动报错: JDWP No transports initialized
- UVA - 10006 - Carmichael Numbers (快速幂+素数判断)
- 操作系统概念学习笔记 1 加电引导过程
- 使用SublimeText 编辑Markdown 文件并预览
- P123 第36题 年月日
- vi 命令
- VS2010简单使用动态链接库流程
- Ubuntu下配置USB转串口及串口工具配置
- 黑马程序员--IOS学习日记:11--Foundation框架
- OC面向对象之---类、对象和方法