2^x mod n = 1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16883    Accepted Submission(s): 5262

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.

 
Sample Input
2
5
 
Sample Output
2^? mod 2 = 1
2^4 mod 5 = 1
 
#include "stdio.h"
int main()
{
int n;
while(~scanf("%d",&n)&&n){
if(n==||n%==){
printf("2^? mod %d = 1\n",n);
continue;
}
else{
int x=,mut=;
mut%=n;
while(mut!=){
x++;
mut=mut*%n;
}
printf("2^%d mod %d = 1\n",x,n);
}
}
return ;
}

开始时Time Limit Exceeded

改进1.n==1情况  2.循环式取余,减少运算量

HDU 1395的更多相关文章

  1. hdu 1395 2^x mod n = 1(暴力题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1395 2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Oth ...

  2. hdu 1395 2^x mod n = 1 (简单数论)

    题目大意: 求出一个最小的x 使得 2的x次方对n取模为1 思路分析: 若要 a*b%p=1  要使得b存在 则 gcd (a,p)=1. 那么我们应用到这个题目上来. 当n为偶数 2^x 也是偶数, ...

  3. (step7.2.1)hdu 1395(2^x mod n = 1——简单数论)

    题目大意:输入一个整数n,输出使2^x mod n = 1成立的最小值K 解题思路:简单数论 1)n可能不能为偶数.因为偶数可不可能模上偶数以后==1. 2)n肯定不可能为1 .因为任何数模上1 == ...

  4. hdu 1395 2^x mod n = 1 暴力过~~最好学下欧拉定理~~~

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. hdu 1395(欧拉函数)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. HDU——1395 2^x mod n = 1(取模运算法则)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  8. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  9. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

随机推荐

  1. python os模块atime ,ctime,mtime意义

    ython的os.stat中主要的时间信息有三个:st_mtime,st_atime,st_ctime.   1.st_mtime:time of last modification      最后一 ...

  2. BeyondCompare3 提示许可证密钥已被撤销解决方法

    今天对比文件提示 许可证密钥已被撤销:3281-0350! 找过了几个注册码还是不行. 正确简单的解决方法: 1.找到 BCState.xml 文件 ​ 2.编辑器打开,删除<TCheckFor ...

  3. Spring框架中ModelAndView、Model、ModelMap的区别

    转自:http://blog.csdn.net/liujiakunit/article/details/51733211 1. Model Model 是一个接口, 其实现类为ExtendedMode ...

  4. 图的同构 (Graph Isomorphism)

    整理摘自:https://www.jianshu.com/p/c33b5d1b4cd9 同构是在数学对象之间定义的一类映射,它能揭示出在这些对象的属性或者操作之间存在的关系.若这两个数学结构之间存在同 ...

  5. MySQL 5.6查看数据库的大小

    1. use information_schema; 2. select concat(round(sum(data_length/1024/1024),2),'MB') as data from t ...

  6. Git&GitHub&GitBook

    一.定义 Git(分布式版本控制系统) GitHub gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub. gitHub于2008年4 ...

  7. DFS(1)——hdu1518Square

    一.题目回顾 题目链接:Square 题意:给你M根木棒,请判断这些木棒能否组成正方形. 二.解题思路 DFS+剪枝 [变量说明] sum:木棒的总长度 ave:形成的正方形的边长 maxlen:最长 ...

  8. Daily Scrum 11.01

    全队进展速度很快,11月伊始都完成了初步的工作.交由负责整合工作的毛宇开始调试整合. Member Today's task  Tomorrow's task 李孟 task 616 测试 (活动) ...

  9. c语言实现带LRU机制的哈希表

    #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  10. not1,not2,bind1st,bind2nd

    例子需要包含头文件 #include <vector> #include <algorithm> #include <functional> bind1st和bin ...