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

Thursday, December 26, 2013

apcer - MayanCalender

MayanCalendar

below given code is for apcer spoj or mayancalender spoj.
code in function first found unlucky day by calculation of JND%7 variable and calculation of JND I actually don't know how it come i just see this some where in vedic math .After that we found unlucky day so we can easily calculate lucky days by subtracting it from total days between that particulars years.After calculation of lucky days is simple............you can do it.........("_")
#include<stdio.h>
long long Lucy_Days(int year1,int year2)
{
 int i,j,count=0,JND,day=21;
 long long total=0;
 for(i=year1;i<=year2;i++)
  for(j=1;j<=12;j++)
  {
   JND =                                                     \
            day                                                      \
         + ((153 * (j + 12 * ((14 - j) / 12) - 3) + 2) / 5) \
         + (365 * (i + 4800 - ((14 - j) / 12)))              \
         + ((i + 4800 - ((14 - j) / 12)) / 4)                \
         - ((i + 4800 - ((14 - j) / 12)) / 100)              \
         + ((i + 4800 - ((14 - j) / 12)) / 400)              \
         - 32045;
         if(JND%7==4)
          count++;
  }
 for(i=year1;i<=year2;i++)
 {
  if((i%4 == 0 && i % 100 != 0)|| i%400==0)
   total=total+366;
  else
   total=total+365;
 }
 return (total-count);
}
int main()
{
 int t;
 scanf("%d",&t);
 while(t--){
  int year1,year2,i;
  scanf("%d%d",&year1,&year2);
  long long lucy=Lucy_Days(year1,year2);
  int A[5]={0,0,0,0,0};
  for(i=4;i>=0;i--)
  {
   if(i==3){
    A[i] = lucy%18;
    lucy = lucy /18;
   }
   else
   {
    A[i] = lucy % 20;
    lucy = lucy / 20;
   }
  }
  for(i=0;i<=4;i++)
  {
   if(i==0)
    printf("%d",A[i]);
   else
    printf(".%d",A[i]);
  }
  printf("\n");
 }
}

1 comment:

Your comment is valuable to us