HDU 1395 2^x mod n = 1(快速幂取模)
来源:互联网 发布:docker web mysql 编辑:程序博客网 时间:2024/05/29 21:29
2^x mod n = 1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15722 Accepted Submission(s): 4871
Problem Description
Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.
Input
One positive integer on each line, the value of n.
Output
If the minimum x exists, print a line with 2^x mod n = 1.
Print 2^? mod n = 1 otherwise.
You should replace x and n with specific numbers.
Print 2^? mod n = 1 otherwise.
You should replace x and n with specific numbers.
Sample Input
25
Sample Output
2^? mod 2 = 12^4 mod 5 = 1
Author
MA, Xiao
Source
ZOJ Monthly, February 2003
AC代码:
#include<iostream>#include<cstdlib>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<cstdlib>#include<iomanip>#include<algorithm>#include<time.h>typedef long long LL;using namespace std;int q_mod(long long a,int b,int c) //快速幂取模 {long long ans=1;while(b>0){if(b&1) //b&1相当于b%2==1 ans=(ans*a)%c; b>>=1; //右移 a=(a*a)%c;}return ans;}int main(){int x,n;while(cin>>n){if(!(n&1)||n<=1)cout<<"2^? mod "<<n<<" = 1"<<endl;else{for(int i=1;;i++)if(q_mod(2,i,n)==1){cout<<"2^"<<i<<" mod "<<n<<" = 1"<<endl;break;}}}}
1 0
- HDU 1395 2^x mod n = 1(快速幂取模)
- HDU 2^x mod n = 1
- HDU 1395 2^x mod n = 1
- hdu 1395 2^x mod n = 1
- HDU 1395 2^x mod n = 1
- hdu 1395-2^x mod n = 1-易超时
- HDU 1395 2^x mod n = 1 数论
- HDU 1395 2^x mod n = 1
- hdu 1395 2^x mod n = 1
- hdu 1395 2^x mod n = 1
- HDU 1395 2^x mod n = 1
- HDU 1395 2^x mod n = 1
- hdu 1395 2^x mod n = 1
- hdu 1395 2^x mod n = 1
- hdu-1395 2^x mod n = 1
- HDU 1395 2^x mod n = 1
- HDU 1395 2^x mod n = 1【数学】
- hdu 1395 2^x mod n = 1
- XStream简单实例
- 采用opencv读取xtion pro live的数据
- 高光谱遥感图像处理(14)-----ENVI使用教程之监督分类与非监督分类
- mycat ShareJoin后少了2条记录的问题剖析详细过程
- 第三届河南省大学生程序设计竞赛题型简要分析
- HDU 1395 2^x mod n = 1(快速幂取模)
- 技术周报 Gif图片 LoadingView
- js 实现数字的进制转换
- bzoj3224普通平衡树 Splay
- ubuntu网络
- Java学习笔记之继承和接口(一) super关键字、final关键字、abstract类和方法
- 图说HashMap多线程并发问题分析
- 剑指offer 面试题24:二叉搜索树BST的后序遍历序列(的判断) 题解
- 安装java和hadoop的过程以及配置环境变量