zoukankan      html  css  js  c++  java
  • 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/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 12146    Accepted Submission(s): 3797


    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
     
    题目大意:暴力搜索,找到合适的X值,这一题可以采取反过来暴力寻找,这一简单易懂些。
    要注意的是输出的值时都要变化的,输出注意一下就好了,毕竟我是wa过的。。。
     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 
     5 int main ()
     6 {
     7     int n;
     8     while (cin>>n)
     9     {
    10         if (n%2&&n>1)
    11         {
    12             int s=1,x=1;
    13             while (x)
    14             {
    15                 s=s*2%n;
    16                 if (s==1)
    17                 {
    18                     printf ("2^%d mod %d = 1
    ",x,n);
    19                     break;
    20                 }
    21                 x++;
    22             }
    23         }
    24         else
    25             printf ("2^? mod %d = 1
    ",n);
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    [BZOJ1303][CQOI2009]中位数图
    [BZOJ1192][HNOI2006]鬼谷子的钱袋
    9.5题解
    9.3题解
    9.2题解
    9.1题解
    8.29题解
    8.28题解
    8.23<2>题解
    8.23<1>题解
  • 原文地址:https://www.cnblogs.com/qq-star/p/3930924.html
Copyright © 2011-2022 走看看