时间限制: 1 s
空间限制: 256000 KB
题目等级 : 青铜 Bronze
题目描述 Description
对于给定的p,编写程序求最小正整数m,n(0<n<m)为何值时,pm与pn的最后三位数字相同。
输入描述 Input Description
一个正整数p(100≤p≤9999)
输出描述 Output Description
一行,最小的m和n,m和n用空格隔开。如有多组,输出最小的m那组。
样例输入 Sample Input
100
样例输出 Sample Output
3 2
数据范围及提示 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 }
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有