/*

2^x mod n = 1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 11800    Accepted Submission(s): 3673

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 i,j,n,s;
while(~scanf("%d",&n)){
if(n==1||n%2==0)
printf("2^? mod %d = 1\n",n);
else{
__int64 s=1;
int i;
for(i=1;;i++){
s*=2;
s%=n; //控制s的值在一定范围内,乘2的同一时候对n取余
if(s==1){ // if(s%n==1)
break;
}
}
printf("2^%d mod %d = 1\n",i,n);
}
}
return 0;
}

2^x mod n = 1 【杭电-HDOJ-1395】 附题的更多相关文章

  1. 循环多少次? 【杭电--HDOJ-1799】 附题+具体解释

    循环多少次? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  2. 最低位 【杭电-HDOJ-1196】 附题

    /* Lowest Bit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. 最小公倍数 【杭电-HDOJ-1108】 附题+具体解释

    /* 最小公倍数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  4. 放大的X 【杭电-2655】 附题

    /* 放大的X Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  5. 大菲波数 【杭电-HDOJ-1715】 附题+具体解释

    /* 大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  6. 不可摸数 【杭电-HDOJ-1999】 附题

    /* hdu 1999 不可摸数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  8. HDU6655 Just Repeat(2019杭电多校J题)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 简单博弈问题,A,B手里各有n,m张牌,牌有颜色,两人轮流出牌(A先出),一个人只能打出对放未打 ...

  9. 【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希

    BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. Windows Azure 网站上的 WordPress 3.8

     编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Sunitha Muthukrishna 和 Windows Azure 网站开发人员体验合作伙伴共同撰写. WordPr ...

  2. zoj 3656 2-sat 不错的题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4879 TLE了一下午.然后没办法了 去搜题解 发现思路跟我的差点儿相同 可是 ...

  3. Linux vsftpd服务配置具体解释

    [背景] 近日.一朋友dominoserver要进行升级.迁移,搭建了linux測试系统,也开启vsftpd服务,但是配置的ftp账号,程序无法正常下载附件. [问题跟踪] 通过ftpclient连接 ...

  4. js数组练习

    //查找数组对象中 age 大于 18 对象 function filterAdult(arr) { return arr.filter(function(item, index, array) { ...

  5. C# Best Practices - Handling Strings

    Features Strings Are Immutable. A String Is a Reference Type Value Type Store their data directly Ex ...

  6. Java代码优化策略

    1.生成对象时,合理分配空间和大小:new ArrayList(100); 2.优化for循环: Vector vect = new Vector(1000); For(int i=0; i<v ...

  7. week4_motion_of_ball_1(小球运动)——改进

    # Ball motion with an explicit timer import simplegui # Initialize globals width = 600 height = 600 ...

  8. KVM镜像管理利器-guestfish使用详解

    原文  http://xiaoli110.blog.51cto.com/1724/1568307   KVM镜像管理利器-guestfish使用详解 本文介绍以下内容: 1. 虚拟机镜像挂载及w2k8 ...

  9. PHP学习建议(来自老手)

    框架太多了,有一个用着,先用熟练,因为框架思想区别不大. 用熟悉一个,再看其他,就容易多.看那么多,没有一个熟悉的,还是什么也不知道. 框架还是要用熟悉才行,然后才是产品如何设计,mysql性能真的有 ...

  10. werkzeug中服务器处理请求的实现

    当成功建立好服务器后,接下来就是等待请求并处理请求通过路由分配给相应的视图函数了,以下是函数调用过程 -> self._handle_request_noblock() /usr/lib/pyt ...