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

i compared my program with others.. whats wrong in my program
Posted by Nandhu 12 Jan 2006 13:41
#include <stdio.h>
#include<math.h>
int main()
{
    double n,m;
    short int y;
    int i;
    char flag='N';
    scanf("%lf%lf%d",&n,&m,&y);
    for (i=1;i<m-1;i++)
    {
        if( (((int)(pow((double)i,n) )) % (int)m) == y)
        {
             printf("%d ",i);
            flag='Y';
        }
    }

    if(flag=='N')
        printf("-1");
    return(0);
}
Re: i compared my program with others.. whats wrong in my program
Posted by wwwwww 13 Jan 2006 11:28
pow(i,n) is a very big number (about 999^999)
So pow(i, n) don't fit into int type.

Try to write yourself Pow() function which
will calculate not i^n but (i^n)%m
And do it in integer numbers!
You don't need double in this problem.
Re: i compared my program with others.. whats wrong in my program
Posted by Nandhu 1 Feb 2006 12:03
Thank you.... now its working..