Where is wrong? I use the O(logn) alg.
#include <iostream>
using namespace std;
int Calc(int x, int n, int m);
int main()
{
int n,m,y;
cin>>n>>m>>y;
for (int i=0;i!=m;++i) {
if (Calc(i,n,m)==y) {cout<<i<<' ';continue;}
if (i==m-1) cout<<-1;
}
return 0;
}
int Calc(int x, int n, int m)
{
if (n==0) return 1;
if (n==1) return x%m;
if (n%2==0) return ( Calc(x,n/2,m)%m )*( Calc(x,n/2,m)%m ) %m;
else return ( ( Calc(x,n/2,m)%m )*( Calc(x,n/2,m)%m )*(x%m) )%m;
}