projecteuler---->problem=19----Counting Sundays
You are given the following information, but you may prefer to do some research for yourself.
- 1 Jan 1900 was a Monday.
- Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine. - A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)
翻译:
现提供你例如以下信息,只是你可能希望自己印证一下。
- 1900年1月1日是星期一
- 除了二月外。四月,六月,九月,十一月,都有30天,其它月份都有31天。
- 二月在平年有28天,在闰年有29天。
- 能被4整除的年份是闰年。只是每一个世纪年(??00)必须能被400整除才是闰年。
请问,在20世纪中(从1901年1月1日到2000年12月31日)总共同拥有多少个月份的第一日是星期天?
def f(year,month):
tmpDay=1
if month == 1 or month == 2:
month += 12
year-=1
if ((year<1752) or (year==1752 and month<9) or (year==1752 and month==9 and tmpDay<3)):
a = (tmpDay + 2*month + 3*(month+1)/5 + year + year/4 +5) % 7;
else:
a = (tmpDay + 2*month + 3*(month+1)/5 + year + year/4 - year/100 + year/400)%7
return a
resu=0
for i in range(1901,2001):
for j in range(1,13):
if f(i,j)==1 :
resu+=1
print resu
版权声明:本文博客原创文章,博客,未经同意,不得转载。
projecteuler---->problem=19----Counting Sundays的更多相关文章
- (Problem 19)Counting Sundays
You are given the following information, but you may prefer to do some research for yourself. 1 Jan ...
- project euler 19: Counting Sundays
import datetime count = 0 for y in range(1901,2001): for m in range(1,13): if datetime.datetime(y,m, ...
- Project Euler 19 Counting Sundays( 蔡勒公式计算星期数 )
题意:在二十世纪(1901年1月1日到2000年12月31日)中,有多少个月的1号是星期天? 蔡勒公式:计算 ( year , month , day ) 是星期几 以下图片仅供学习! /****** ...
- Problem 19
Problem 19 You are given the following information, but you may prefer to do some research for yours ...
- Project Euler:Problem 76 Counting summations
It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...
- Python练习题 046:Project Euler 019:每月1日是星期天
本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...
- Problem 28
Problem 28 https://projecteuler.net/problem=28 Starting with the number 1 and moving to the right in ...
- Problem 42
Problem 42 https://projecteuler.net/problem=42 The nth term of the sequence of triangle numbers is g ...
- 欧拉工程第72题:Counting fractions
题目链接:https://projecteuler.net/problem=72 真分数;n/d 当d ≤ 1,000,000时候的真分数有多少个 public class P72{ void run ...
- 欧拉工程第73题:Counting fractions in a range
题目链接:https://projecteuler.net/problem=73 n/d的真分数 ,当d<=12000时 在 1/3 and 1/2 之间的有多少个 public class P ...
随机推荐
- RH133读书笔记(2)-Lab 2 Working with packages
Lab 2 Working with packages Goal: To gain working experience with package management System Setup: A ...
- Directx11学习笔记【六】 基本的数学知识----矩阵篇
参考dx11龙书 Chapter2 matrix algebra(矩阵代数) 关于矩阵的一些基本概念定理(例如矩阵加减乘法,逆矩阵,伴随矩阵,转置矩阵等)可以参考维基百科 https://zh.wik ...
- 【Java技术位】——代理模式及其事务包
背景 项目中我们会遇到这种情况:在几个方法中增加同样的代码,这些代码是与业务无关的,而且以后有可能因为考虑不周或需求变动再或者是其它原因,我们须要对他们进行逐一进行修改.举个详细的样例,比方程序中的日 ...
- asm 盘头损失,破坏
BUG 14693394 – ORA-15196: INVALID ASM BLOCK HEADER [KFC.C:26076] [ENDIAN_KFBH] BUG 14758001 – ORA-15 ...
- j经常使用ava应用server
什么是应用server它?它主要提供的执行环境的应用程序,为组件提供服务. 要了解更多关于,您可以查看我的博客:何为容器? Java 的应用server非常多,从功能上分为两类:WEB 应用serve ...
- ZOJ1463:Brackets Sequence(间隙DP)
Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular seque ...
- HDU 5095 Linearization of the kernel functions in SVM(模拟)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5095 Problem Description SVM(Support Vector Machine) ...
- WWDC 2014 Session 205/217 Extension 注意事项
基于阅读下面的内容205和217的PDF做笔记.没有深入研究. 205 Creating Extensions for iOS and OS X, Part 1 217 Creating Extens ...
- linux处置服务Iptables
一:Iptables防火墙服务 iptables分为两个部分:一个部分在内核中实现,一个为用户接口命令iptables,用户通过该命令来改动防火墙的功能.所以,iptables要使用对应的功能.必需要 ...
- Partitioner分区过程分析
Partition中国人意味着分区,意义的碎片,这个阶段也是整个MapReduce该过程的第三阶段.在Map返回任务,是使key分到通过一定的分区算法.分到固定的区域中.给不同的Reduce做处理,达 ...