poj 3641
2015-11-04 20:34
197 查看
根据题目的定义来做,考quick_mod的应用,比较水
View Code
#include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <queue> #include <map> #include <algorithm> #include <vector> #include <cmath> using namespace std; const int maxn = 1000005; typedef long long LL; vector<int>G[maxn]; bool prim(LL n) { int t = (int)sqrt(n)+1; if( n == 2 || n == 1) return 1; LL i; for(i=2;i<=t;i++){ if(n%i == 0){ return 0; break; } } return 1; } LL quick_mod(LL a,LL b,LL m) { LL ans = 1; while(b){ if(b&1){ ans = (ans*a)%m; } b>>=1; a = a*a%m; } return ans; } int main() { LL a,n,p,b; while(cin>>p>>a&&(a+p)){ if(prim(p)) puts("no"); else{ LL ans = 1; ans = quick_mod(a,p,p); if(ans == a) puts("yes"); else puts("no"); } } return 0; }
View Code
相关文章推荐
- (转载)SQL语句中Group by语句的详细介绍
- 小甲鱼:Python学习笔记002_数组_元组_字符串
- 将三个数从大到小输出
- 互联网MySQL开发规范
- java中Map和List初始化的两种方法
- 《剑指offer》——二进制中1的个数
- Swift枚举代码
- 安装Windows下 CDH5开发环境
- 【Android架构设置篇】之设置界面添加并实现永不休眠功能
- 基于opencv的相机之最初布局(一)
- 黑马程序员—Java基础—IO3
- [leetcode 102] Binary Tree Level Order Traversal
- 201511042030_《JavaScript——DOM 》
- 求命题真值表及主范式
- android 布局管理器 各种布局简介
- 夏洛特的网 ——看《夏洛特的网》
- 腾讯防刷负责人:基于用户画像大数据的电商防刷架构
- CYC-UISearchBar 点击空白回收键盘
- NSRunLoop详解
- Linux命令——whoami