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? Give me some test!!!!
Posted by sonteenzz 10 Jul 2003 21:52
#include <stdio.h>
int modu(int A,int n,int p){
    int i=0,temp=1;
    if (n==0)
        if(A!=0)
            return 1;
        else
            return -1;
    if (!(A%p))
        return 0;
    if (A>p)
        return modu(A%p,n,p);
    else{
        if (n%2){
            if (n-1>=2){
                return modu(((A*A)%p)*A,
(n-1)/2,p);
            }else{
                return A%p;
            }
        }else{
            if (n>=2){
                return modu((A*A)%
p,n/2,p);
            }else{
                return A%p;
            }
        }
    }
}
int main(){
    int A=0,M,n,p;
    char k=0;
    scanf("%d %d %d",&n,&M,&p);
    for (A=0;A<M;A++){
        if (modu(A,n,M)==p){
            k++;
            if(k>1)
                printf(" ");
            printf("%d",A);
        }
    }
    if (!k)
        printf("-1");
    return 0;
}
Re: WA? Give me some test!!!!
Posted by Dinu Adrian Florin 10 May 2004 17:50
Stupid source. How did you make it so big?