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 }