ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1110. Power

TUIT_MAD Wy WA on test , Please help me [2] // Problem 1110. Power 30 Mar 2008 13:06
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main()
{
      #ifndef ONLINE_JUDGE
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
            #endif

    int n,m,y;
    long double x;
    long double time;
    vector< long double >vec;

    cin >> n >> m >> y;
    if( n <= 0 || n >= 999)
        exit(1);
    if( m <= 1 || m >= 999)
        exit(1);
    if( y <= 0 || y >= 99)
        exit(1);

    for( x = 0; x < m; x++)
    {
        time = pow(x, n);
        if( (unsigned long)time % m == y)
            vec.push_back(x);
    }
    if( vec.size() == 0)
        cout << "-1";

    else
    {
    for( unsigned int i = 0; i < vec.size(); i++)
    {
        cout << vec[i] << " ";
    }
    }

    return 0;
}
SubmitRush Re: Wy WA on test , Please help me [1] // Problem 1110. Power 1 Oct 2009 11:30
Don't use pow~
Actually, the result of pow can exceed your data type(long).

tips.
(A*A) mod m = (A mod m) * (A mod m)

Edited by author 01.10.2009 11:32
PrankMaN Re: Wy WA on test , Please help me // Problem 1110. Power 23 Mar 2013 02:52
(A * A) mod m = ((A mod m) * (A mod m)) mod m