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

Why I got Wrong Answer
Posted by 555 31 Jan 2002 20:30
This is my program : (in C++)

#include <stdio.h>

long P(long a,long n)
{
    long re=1;
    for(long i=1;i<=n;i++)
        re*=a;
    return re;
}

long n,m,y;

long f(long i)
{
    return P(i,n)%m;
}

void main()
{
    int first=1;
    scanf("%ld%ld%ld",&n,&m,&y);
    for(long i=0;i<m;i++)
    {
        if(f(i)==y)
        {
            if(first)
            {

    printf("%ld",i);

    first=0;
            }
            else

    printf(" %ld",i);
        }
    }
    if(first) printf("-1");
}
//End of program

Help me please!
Your P function is incorrect, it may be longer than 2^31-1 :)
Posted by Miguel Angel 1 Feb 2002 02:16
> This is my program : (in C++)
>
> #include <stdio.h>
>
> long P(long a,long n)
> {
>     long re=1;
>     for(long i=1;i<=n;i++)
>         re*=a;
>     return re;
> }
>
> long n,m,y;
>
> long f(long i)
> {
>     return P(i,n)%m;
> }
>
> void main()
> {
>     int first=1;
>     scanf("%ld%ld%ld",&n,&m,&y);
>     for(long i=0;i<m;i++)
>     {
>         if(f(i)==y)
>         {
>             if(first)
>             {
>
>     printf("%ld",i);
>
>     first=0;
>             }
>             else
>
>     printf(" %ld",i);
>         }
>     }
>     if(first) printf("-1");
> }
> //End of program
>
> Help me please!