Submit | All submissions | Best solutions | Back to list |
APCER - MayanCalendar |
The Maya is a Mesoamerican civilization noted for its art, architecture, mathematics and astronomical systems. In the recent past their calendar system has been quite in the news because of the misinterpretation of their Long count calendar, which gave way for a popular belief that a cataclysm will take place on December 21, 2012. Many speculated it will mark the end of human civilization!
But we now know it did not happen as we are still alive! Note this date, it falls on a Friday. Since human civilization may have ended on that day, we will call every Friday the 21st as a vulnerable day. Similarly we define a safe day which is not a vulnerable day. Your task is given two years M and N, you need to find how many safe days are there between any given years M and N (inclusive).
To honor the Mayan civilization you should write the total number of safe days in Mayan Long Count notation. The Long Count calendar identifies a date by counting the number of days from the Mayan creation date. But instead of using a base-10 scheme like Western numbering, the Long Count days were tallied in a modified base-20 scheme. As a matter of fact December 21, 2012 is simply the day that the calendar will go to the next B'ak'tun. You do not need to bother about creation date but simply represent your answer in Long Count notation. See the below example and table for clarification:
Days | Place | Long Count unit |
1 | 0 | 1 K'in |
20 | 1 | 1 Winal |
360 | 2 | 1 Tun |
7,200 | 3 | 1 K'atun |
144,000 | 4 | 1 B'ak'tun |
Table of Long Count units
Check the full list here: en.wikipedia.org/wiki/Maya_calendar (not needed for this problem).
Conversion
For this problem you can consider numbers in the Long Count to be represented in base 20 except for the Winal place which is to be taken in base 18. Below example will clarify how to convert your answer into Long Count Notation.
For instance, if safe days comes out to be 1454 your output must be: "0.0.4.0.14" (without quotes). (1*14 + 20*0 + 360*4 + 7200*0 + 144000*0 = 1454)
For 360 output must be "0.0.1.0.0" (without quotes).
For 20 output must be “0.0.0.1.0” (without quotes).
As you can see all the places are in base 10 except the 1st place which is base 18.
Input
First line of input contains 0 < T < 500, number of test cases on which your program will run. Followed by two integers M and N where 1901 <= M, N <= 2300, where M <= N, if M = N you need to tell for that particular year only.
Output
For every test case output: A single line containing the number of safe days between the year M and N (inclusive) in Long count notation explained above. It is guaranteed that the number of safe days could always be represented up to fourth place (B'ak'tun place) in the above given notation.
"a.b.c.d.e" (without quotes) where 0 <= a, b, c, e < 20, 0 <= d < 18.
Facts
- Jan 1, 1901 was Tuesday.
- All calculations must be done following Gregorian calendar which is the current standard calendar in the world including ours.
- If you don't know how to calculate leap year see this link: en.wikipedia.org/wiki/Leap_year
Sample
Input: 3 2011 2012 2012 2012 2000 2020 Output: 0.0.2.0.7 0.0.1.0.4 0.1.1.3.14
Explanation
For case 1: there are 727 safe days which can be represented as 0.0.2.0.7
There are 4 vulnerable days between: January 2011 to December 2012.
These are: 21st January 2011, 21st October 2011, 21st September 2012 and 21st December 2012.
Total number of days between: January 2011 to December 2012 are 731.
Therefore the number of safe days are 731-4 = 727.
Added by: | Rishabh Baid |
Date: | 2013-01-18 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | http://www.spoj.com/CRESCENT/ |
hide comments
2017-11-14 09:50:54
Always fun to learn something outside the algo/structures realm while solving. Pay no attention to the base-20 gibberish, just look at the example conversion of 1454. |
|
2015-12-30 17:28:30
easy problem.AC in 2nd go. HINT:USE Calendar ;) |
|
2015-07-18 09:06:52
Doomday Rule Zeller’s Rule....for those who are not willing to use multiple if-else statements!!! Last edit: 2015-07-18 09:09:59 |
|
2014-12-02 11:41:09 Diksha Jaiswal
finally accepted after 7 WAs...nice prblm (y) :) Last edit: 2014-12-03 06:28:01 |
|
2014-08-26 20:23:41 Rishabh Baid
Done. Thanks for pointing it out. |
|
2014-08-26 20:22:11 Pratyush Kumar
(1*14 + 20*0 + 360*4 + 7200*0 + 1444000*0 = 1454) 1444000 should be modified to 144000 |