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

int - AC, but long long - WA 2, Why?
Posted by Maria Pukhlyakova [Tomsk PU] 29 Aug 2010 21:41
You can see two program with one difference - type. What wrong with first program?

define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <utility>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

long long n, m, y, x;
bool yes = 0;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%lld%lld%lld",&n,&m,&y);
    for (int i = 0; i < m; ++i)
    {
        x = i;
        if (n == 0) x = 1;
        for (int j = 2; j <= n; ++j)
            x = (x*i)%m;
        if (x%m == y)
        {
            yes = 1;
            printf("%lld", i);
            printf(" ");
        }
    }
    if (!yes) printf("-1");
    return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <utility>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

int n, m, y, x;
bool yes = 0;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d%d",&n,&m,&y);
    for (int i = 0; i < m; ++i)
    {
        x = i;
        if (n == 0) x = 1;
        for (int j = 2; j <= n; ++j)
            x = (x*i)%m;
        if (x%m == y)
        {
            yes = 1;
            printf("%d", i);
            printf(" ");
        }
    }
    if (!yes) printf("-1");
    return 0;
}