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

WA#4
Posted by [TH0412]tdson 27 Dec 2012 08:31
#include<iostream>
#include<cmath>
using namespace std;

int tinh(int x, int n)
{
    int temp = 1;
    for(int i = 0; i < n; i++)
        temp *= x;
    return temp;
}

void main()
{
    int n, m, y, x;
    bool flag = true;
    cin >> n >> m >> y;

    for(x = 0; x < m; x++)
    {
        if(tinh(x, n)%m == y)
        {
            cout << x << " ";
            flag = false;
        }
    }
    if(flag)
        cout << -1;
}
Re: WA#4
Posted by mythysjh 5 Jan 2013 09:15
tinh(x, n) may produce a very big number that leading overflow