2013
11-10

Calendar

A calendar is a system for measuring time, from hours and minutes, to months and days, and finally to years and centuries. The terms of hour, day, month, year and century are all units of time measurements of a calender system.

According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years.

Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.

The input consists of lines each containing a positive integer, which is the number of days that have elapsed since January 1, 2000 A.D. The last line contains an integer −1, which should not be processed.

You may assume that the resulting date won’t be after the year 9999.

For each test case, output one line containing the date and the day of the week in the format of “YYYY-MM-DD DayOfWeek”, where “DayOfWeek” must be one of “Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday” and “Saturday”.

1730
1740
1750
1751
-1

2004-09-26 Sunday
2004-10-06 Wednesday
2004-10-16 Saturday
2004-10-17 Sunday

import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.*;

public class Main{
public static void main(String[] args) throws IOException{
Date twoK,res,t1,t2;
long twoKl,resl,t;
//“EEEE”超过4位为全称，如果不加上后面的“Locale.US”，星期会输出中文哦！
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd EEEE",Locale.US);
//BufferedInputStream bin = new BufferedInputStream(new FileInputStream("in.txt"));
//System.setIn(bin);
Scanner cin = new Scanner(System.in);
twoK = new Date(100,0,1,8,0,0);
twoKl=twoK.getTime();
t1 = new Date(100,0,1,8,0,0);
t2 = new Date(100,0,2,8,0,0);
t=t2.getTime()-t1.getTime();//计算一天的getTime()差值
while(cin.hasNext())
{
resl=cin.nextLong();
if(resl==-1)
{
break;
}
resl=resl*t+twoKl;
res = new Date(resl);
System.out.println(sdf.format(res));
}
}
}

1. 为什么for循环找到的i一定是素数叻，而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak，而你每次取余都用的是原来的m，也就是n

2. 换句话说，A[k/2-1]不可能大于两数组合并之后的第k小值，所以我们可以将其抛弃。
应该是，不可能小于合并后的第K小值吧

3. simple, however efficient. A lot of instances it is difficult to get that a??perfect balancea?? among usability and appearance. I must say that youa??ve done a exceptional task with this. Also, the blog masses quite fast for me on Web explore.