|
|
back to boardWhy 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 :) > 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! |
|
|