3085 same last three, 3085 three

Source: Internet
Author: User

3085 same last three, 3085 three
3085 same last three

 

Time Limit: 1 s space limit: 256000 KB title level: Bronze Title Description Description

For the given p, write the program to find the minimum positive integer m, n (0 <n <m) Why the value, pm and the last three digits of pn are the same.

Input description Input Description

A positive integer p (100 ≤ p ≤ 9999)

Output description Output Description

One row. The minimum m and n, m and n are separated by spaces. If there are multiple groups, output the smallest m group.

Sample Input Sample Input

100

Sample output Sample Output

3 2

Data range and prompt Data Size & Hint

100 ≤ p ≤ 9999

 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 int f(int x,int n) 6 { 7     int now=1; 8     while(n) 9     {10         if(n&1)11         {12             now=now*x%1000;13         }14         x=x*x%1000;15         n>>=1;16     }17     return now%1000;18 }19 int main()20 {21     int p;22     cin>>p;23     for(int i=1;i<=1000;i++)24     {25         for(int j=1;j<=i;j++)26         {27             int x=f(p,i);28             int y=f(p,j);29             if(x==y&&i!=j)30             {31                 cout<<i<<" "<<j;32                 return 0;33             }34         }35     }36     return 0;37 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.