Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com

And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Tuesday, February 4, 2014

PUCMM009-David and his Obsession

                                              David and his Obsession
given below code is for pucmm009 spoj or David and his Obsession spoj.
you can just do it by calculating probability on paper and print it. answer is 1/420.
#include <stdio.h>
#include <cstdlib>
int gcd(int a,int b)
{
 if(a==0)
  return b;
 return gcd(b%a,a);
}
int main()
{
 int k,num,count=0,first,i,flage=1;
 for(k=3;k<=202;k++)
 {
  flage=1;
  num=k*495;
  if(k<=20)
  {
   int *dig;
   dig=(int *)calloc(10,sizeof(int));
   while(num!=0 )
   {
    if(num%10==0 || dig[num%10]==1)
    {
     flage=0;
     break;
    }
    dig[num%10]=1;
    num/=10;
   }
   if(flage)
    count++;
  }
  else{
   int *dig;
    dig=(int *)calloc(10,sizeof(int));
   while(num!=0)
   {
    if(dig[num%10]==1)
    {
     flage=0;
     break;
    }
    dig[num%10]=1;
    num/=10;
   }
   if(flage)
    count++;
  }
 }
 int temp=gcd(count,30240)
 printf("%d/%d",count/temp,30240/temp);
 return 0;
}

No comments:

Post a Comment

Your comment is valuable to us