zoukankan      html  css  js  c++  java
  • 2^x mod n = 1(hd1395)

    2^x mod n = 1

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


    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
     1 #include <iostream>
     2 using namespace std;
     3 int main()
     4 {
     5     int n,i,j;
     6     while(cin>>n)
     7     {
     8         int x=2;
     9         if(n==1||n%2==0)
    10         {
    11             cout<<"2^? mod "<<n<<" = 1
    ";
    12             continue;
    13         }
    14         for(i=0;;i++)
    15         {
    16             if(x==1)
    17                 break;
    18             else
    19             {
    20                 x=x*2;
    21                 x=x%n;
    22             }
    23         }
    24         cout<<"2^"<<i+1<<" mod "<<n<<" = 1"<<endl;
    25     }
    26 }
     
  • 相关阅读:
    HTML笔记
    html文本格式化
    标题大小与字体大小的关系
    html学习笔记
    冒泡排序
    直接插入算法
    绘制针状图
    绘制矢量图
    饼图pie 或者pie3
    三维直方图
  • 原文地址:https://www.cnblogs.com/a1225234/p/4682901.html
Copyright © 2011-2022 走看看