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 WA on test#4?
Posted by mkrzyzu 19 Mar 2010 02:24
nvm.

Edited by author 25.03.2010 20:45
Re: Why WA on test#4?
Posted by nguyenductam 17 Apr 2010 21:08
Code got AC:
#include<stdio.h>
// #include<conio.h>

int kq[200];

int Mod(int x,int n,int m);
void Sort(int l,int r);

int main()
{
    int n,m,y,i;
    int t=0;
    scanf("%d%d%d",&n,&m,&y);
    for(i=0;i<m;i++)
                    if(Mod(i,n,m)==y)
                    {
                     t++;
                     kq[t]=i;
                    }
    if(t==0) printf("%d",-1);
    else
    {
     Sort(1,t);
     for(i=1;i<=t;i++) printf("%d%s",kq[i]," ");
    }
   // getch();
    return 0;
}
int Mod(int x,int n,int m)
{
 if(n==0) return 1;
 if(n%2==0)
 {
  return (((Mod(x,n/2,m)%m)*(Mod(x,n/2,m)%m))%m);
 }
 else return ((Mod(x,n-1,m)*x)%m);
}
void Sort(int l,int r)
{
 int t,p,g,mid,tam;
 t=l;
 p=r;
 g=(t+p)/2;
 mid=kq[g];
 while(t<=p)
 {
  while(kq[t]<mid) t++;
  while(kq[p]>mid) p--;
  if(t<=p)
  {
   tam=kq[t];
   kq[t]=kq[p];
   kq[p]=tam;
   t++;
   p--;
  }
 }
 if(t<r)Sort(t,r);
 if(l<p)Sort(l,p);
}