poj 3641 Pseudoprime numbers
2015-09-01 17:40
471 查看
原题链接:http://poj.org/problem?id=3641
快速幂。。
快速幂。。
[code]#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<vector> #include<set> using std::min; using std::sort; using std::pair; using std::swap; using std::vector; using std::multiset; #define pb(e) push_back(e) #define sz(c) (int)(c).size() #define mp(a, b) make_pair(a, b) #define all(c) (c).begin(), (c).end() #define iter(c) __typeof((c).begin()) #define cls(arr, val) memset(arr, val, sizeof(arr)) #define cpresent(c, e) (find(all(c), (e)) != (c).end()) #define rep(i, n) for(int i = 0; i < (int)n; i++) #define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i) const int N = 1 << 17; const int INF = ~0u >> 1; typedef unsigned long long ull; bool isPrime(ull n) { for(int i = 2; (ull)i * i <= n; i++ ) { if(n % i == 0) { return false; } } return n != 1; } ull mod_pow(ull a, ull p) { ull ans = 1, M = p; while(p) { if(p & 1) ans = ans * a % M; a = a * a % M; p >>= 1; } return ans; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout); #endif ull a, p; while(~scanf("%lld %lld", &p, &a), a + p) { if(isPrime(p)) { puts("no"); continue; } puts(a % p == mod_pow(a, p) ? "yes" : "no"); } return 0; }
相关文章推荐
- nginx servername配置域名网站可以正常登录,servername配置IP+Port却无法正常登录
- 《得知opencv》注意事项——矩阵和图像处理——cvAdd、cvAddS and cvAddWeighted
- shell 将变量当命令执行问题【多条命令同时执行问题】
- 第五章 设计程序架构 之 设计缓存策略
- Shell中的${}、##和%%使用范例
- 一个查看贝塞尔曲线效果的网站
- mysql官网下载mysql时无法自动刷新到linux版本,解决办法
- 让程序在 linux 后台运行的集中方式
- 解决Exception: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z等一系列问题
- nginx转发请求
- linux find 命令的详解
- Linux 初学杂记
- linux时间互转
- Nginx + Rtmp 实现rtmp和HLS直播流,同时实现时移(分段录制回放)功能
- Linux中Tomcat 自动设置CATALINA_HOME方法
- centos安装mediawiki
- Docker实践
- Linux 下 LVS+Keepalived 负载均衡安装
- Android (Linux) Suspend流程
- 关闭Linux里边的selinux