Power URAL - 1110
2017-04-10 17:55
295 查看
You are given the whole numbers N, M and Y. Write a program that will find all whole numbers X in the interval [0, M − 1] such that XN mod M = Y. Input The input contains a single line with N, M and Y (0 < N < 999, 1 < M < 999, 0 < Y < 999) separated with one space. Output Output all numbers X separated with space on one line. The numbers must be written in ascending order. If no such numbers exist then output −1. Example input output 2 6 4 2 4 //这题虽然水,但是我没做出来,做了好几次 AC代码 #include<iostream> #include<iomanip> #include<math.h> #include<string.h> using namespace std; int b[1005]; int main() { int n,m,y,a; memset(b,0,sizeof(b)); cin>>n>>m>>y; int count=0; int i; for(i=0;i<m;i++) { //a=pow(i,n); a=1; for(int j=0;j<n;j++) {//利用a*b%c=((a%c)*b)%c,每一步都进行这种处理 a*=(i%m); a=a%m; } if(a%m==y) { count++; b[count]=i; } } if(count==0) cout<<"-1"<<endl; else { for(int k=1;k<=count;k++) { if(k==count) cout<<b[k]; else cout<<b[k]<<" "; } } return 0; }
相关文章推荐
- ural 1110 Power
- ural 1110 Power
- URAL 1920 Titan Ruins: the Infinite Power of Magic
- ural 1110,快速幂
- URAL 1110. Power
- URAL 1920 Titan Ruins: the Infinite Power of Magic
- URAL 1920 Titan Ruins: the Infinite Power of Magic
- URAL - 1920 Titan Ruins: the Infinite Power of Magic(乱搞)
- 1110. Power
- Ural1110(数论)
- ural1057 Amount of Degrees
- Timus - 1110. Power 除尽问题
- URAL 1010 Discrete Function
- Eclipse中Easy Shell插件配置PowerCmd
- URAL 1775 Space Bowling
- power eat responsibility
- 【Ural1057】幂和的数量
- URAL 1519 Formula 1
- URAL 1654 Cipher Message
- URAL 1297(Palindrome,后缀数组)最长回文串