atcoder 它February 29th

Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB

Problem

Charlie was born January 1st of the year A, on the Earth. He will leave the Earth on December 31st of the year B.

He wants to know how many times he passes February 29th on the Earth.

February 29th is a leap day. A year that contains a leap day is called a leap year. You can determine if a year is leap year or not by following rules.

  • If the year is divisible by 4, it is a leap year except the following case.
  • If the year is divisible by 100, it is NOT a leap year except the following case.
  • If the year is divisible by 400, it is a leap year.

Output how many times Charlie passes February 29th on the Earth. Note that Charlie lives very long.


Input

The input will be given in the following format from the Standard Input.

A B
  • On the first line, you will be given the year A(1≦A≦2,000,000,000), when Charlie born, followed by a space and the year B(AB≦2,000,000,000), when he leaves the Earth.

Achievements and Points

  • When you pass every test case where 1≦AB≦3,000 , you will be awarded 25 points.
  • In addition, if you pass all the rest test cases you will be awarded 25 more points.

Output

Output how many times Charlie passes February 29th on the Earth in one line. Make sure to insert a line break at the end of the output.


Inout Example 1

 
     
  1. 1988 2014

Output Example 1

 
     
  1. 7

Charlie can pass February 29th of 1988199219962000200420082012. The total is 7 times.


Input Example 2

 
     
  1. 997 1003

Output Example 2

 
     
  1. 0

Note that the year 1000 is NOT a leap year.


Input Example 3

 
     
  1. 1 2000000000

Output Example 3

 
     
  1. 485000000

Note that Charlie lives very long.

思路:这题就是求两个年份之间的闰年数目。简单题。直接上代码。

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int temp1=b/4-(a-1)/4;
			int temp2=b/100-(a-1)/100;
			int temp3=b/400-(a-1)/400;
			System.out.println(temp1-temp2+temp3);
		}
	}
}


版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值