标签:
input | output |
---|---|
2 6 4 |
2 4 |
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int m; int fast_mi(int a,int k) { int res=1; while(k) { if(k&1) res=res*a%m; a=a*a%m; k>>=1; } return res; } int main() { int n,y,i; int a[1000]; while(cin>>n>>m>>y) { int flag=0; memset(a,0,sizeof(a)); int len=0; for(i=0; i<=m-1; i++) { if(fast_mi(i,n)%m==y) { flag=1; a[len++]=i; } } if(flag) { for(i=0; i<len; i++) { if(!i) cout<<a[i]; else cout<<" "<<a[i]; } cout<<endl; } else cout<<-1<<endl; } return 0; }
标签:
原文地址:http://blog.csdn.net/sky_miange/article/details/45343685