Forum Index



Reply to topic
Smith
Radbug
SUPREME DRINKER
SUPREME DRINKER
Radbug
Joined: 16 Oct 2009
Posts: 17
Reply with quote
Code:
#include <iostream.h>
#include <fstream.h>
int main ()
{
   ifstream fin("smith.in");
   ofstream fout("smith.out");
   unsigned long N,S,x,d,Sd,Sp,prim,y;
   double rad;
   fin>>N;
   prim=1;
   if(N%2==0)
      prim=0;
   else
      {
         d=3;
         rad=sqrt(N);
         while(d<=rad && N%d!=0)
            d=d+2;
         if (d<=rad)
            prim=0;
      }
   if (prim==0)
   {   
      x=N;
      S=0;
      while(x>0)
      {
         S=S+x%10;
         x=x/10;
      }
      x=N;
      d=2;
      Sp=0;
      while (x>1)
      {
         if (x%d==0)
         {
            y=d;
            Sd=0;
            while    (y>0)
            {
               Sd=Sd+y%10;
               y=y/10;
            }
            while (x%d==0)
               {
                  x=x/d;
                  Sp=Sp+Sd;
               }
         }
         d++;
      }
      if (S==Sp)
            fout<<"DA";
         else
            fout<<"NU";
   }
   fin.close();
   fout.close();
   return 0;
}
View user's profileSend private message
Smith
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT + 2 Hours  
Page 1 of 1  

  
  
 Reply to topic