Timus : 1110 (Power)



// http://acm.timus.ru/problem.aspx?space=1&num=1110
// Tag: mod 

#include <stdio.h>
#include <vector>
using namespace std;
 
int main(int argc, char *argv[])
{
        int n, m, y; scanf ("%d %d %d", &n, &m, &y);
        vector <int> output;
 
        for (int x = 0; x < m; x++ )
        {
                int res = 1;
                for (int i = 1; i <= n; i++ )
                {
                        res *= x;
                        res %= m;
                }
 
                if ( res == y )
                {
                        output.push_back (x);
                }
        }
 
        if ( output.size () == 0 )
        {
                printf ("-1\n");
        }
        else {
                printf ("%d", output [0]);
                for ( size_t i = 1; i < output.size (); i++ )
                {
                        printf (" %d", output [i]);
                }
                printf ("\n");
        }
        
        return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s