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 1095. Nikifor 3

Why WA 5? Is there some special case which I could've missed ?
Posted by Todor Tsonkov 19 Jul 2006 13:24
int pre[8]={4123,1324,1234,1324,1243,2413,2134,4123};

LL solve(LL n)
{
     if (n/10000==0)
     return 4123;

     int k,j,i,p,b[5]={0};
     LL m=0;
     LL res=10000;
     while (true)
      {
          p=n%10;
          n/=10;

          if (p==0)
             b[0]++;
          else
          if (p==1 && !b[1])
           b[1]=1;
           else
          if (p==2 && !b[2])
           b[2]=1;
           else
           if (p==3 && !b[3])
           b[3]=1;
           else
           if (p==4 && !b[4])
           b[4]=1;
            else
             {
                  m+=p*res;
                  res*=10;
             }
             if(n==0) break;
      }

      if (m==0)
      {
         i=-1;
         res=1;
         for (j=1;j<=b[0];j++)
          res*=(LL)10;
          while (true)
          {
              i++;
              if ((pre[i]*res)%7==0)
                 break;
          }
          return pre[i]*res;
      }
      else
      if(b[0]>0)
       {
        for (i=0;i<b[0];i++)
        {
         m*=(LL)10;
         res*=(LL)10;
        }
        k=m%7;
        return m+pre[7-k];
       }

      else
      {
      k=m%7;
      m+=pre[7-k];
      return m;
      }
}

where LL is unsigned long long. Can give me some tests if possible

Edited by author 19.07.2006 14:18
Re: Why WA 5? Is there some special case which I could've missed ?
Posted by fredAC 10 Sep 2009 20:15
wa too,trace my code
remainder[7-((a%7)*4)%7],so when a%7 ==0;
the remainder[7] is uninitilized,