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

where is my error ....... i got WA
Posted by GoGo 25 Mar 2002 20:28
#include <stdio.h>

long n,m,y,x;

void read_data()
 {
  FILE *f=stdin;
  fscanf(f,"%ld%ld%ld",&n,&m,&y);
 }

long expon_modul(int a)
 {
  long c=0,d=1,i;
  for(i=15;!(n & (1 << i));i--);
  for(;i>=0;i--)
   {
    c*=2;
    d=(d*d)%m;
    if(n & (1 << i))
     {
      c++;
      d=(d*a)%m;
     }
   }
  return(d);
 }

void solve()
 {
  long i;
  if(!y)printf("0 ");
  for(i=1;i<m;i++)
   if(expon_modul(i)==y)printf("%ld ",i);
 }

void main()
 {
  read_data();
  solve();
 }
read the output specification again
Posted by MadPsyentist/Sam 26 Mar 2002 18:12
> #include <stdio.h>
>
> long n,m,y,x;
>
> void read_data()
>  {
>   FILE *f=stdin;
>   fscanf(f,"%ld%ld%ld",&n,&m,&y);
>  }
>
> long expon_modul(int a)
>  {
>   long c=0,d=1,i;
>   for(i=15;!(n & (1 << i));i--);
>   for(;i>=0;i--)
>    {
>     c*=2;
>     d=(d*d)%m;
>     if(n & (1 << i))
>      {
>       c++;
>       d=(d*a)%m;
>      }
>    }
>   return(d);
>  }
>
> void solve()
>  {
>   long i;
>   if(!y)printf("0 ");
>   for(i=1;i<m;i++)
>    if(expon_modul(i)==y)printf("%ld ",i);
>  }
>
> void main()
>  {
>   read_data();
>   solve();
>  }