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----&gt;problem=19----Counting Sundays的更多相关文章

  1. (Problem 19)Counting Sundays

    You are given the following information, but you may prefer to do some research for yourself. 1 Jan ...

  2. 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, ...

  3. Project Euler 19 Counting Sundays( 蔡勒公式计算星期数 )

    题意:在二十世纪(1901年1月1日到2000年12月31日)中,有多少个月的1号是星期天? 蔡勒公式:计算 ( year , month , day ) 是星期几 以下图片仅供学习! /****** ...

  4. Problem 19

    Problem 19 You are given the following information, but you may prefer to do some research for yours ...

  5. 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 ...

  6. Python练习题 046:Project Euler 019:每月1日是星期天

    本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...

  7. Problem 28

    Problem 28 https://projecteuler.net/problem=28 Starting with the number 1 and moving to the right in ...

  8. Problem 42

    Problem 42 https://projecteuler.net/problem=42 The nth term of the sequence of triangle numbers is g ...

  9. 欧拉工程第72题:Counting fractions

    题目链接:https://projecteuler.net/problem=72 真分数;n/d 当d ≤ 1,000,000时候的真分数有多少个 public class P72{ void run ...

  10. 欧拉工程第73题:Counting fractions in a range

    题目链接:https://projecteuler.net/problem=73 n/d的真分数 ,当d<=12000时 在 1/3 and 1/2 之间的有多少个 public class P ...

随机推荐

  1. 返璞归真 asp.net mvc (6) - asp.net mvc 2.0 新特性

    原文:返璞归真 asp.net mvc (6) - asp.net mvc 2.0 新特性 [索引页][源码下载] 返璞归真 asp.net mvc (6) - asp.net mvc 2.0 新特性 ...

  2. 开源Math.NET基础数学类库使用(07)一些常用的数学物理常数

    原文:[原创]开源Math.NET基础数学类库使用(07)一些常用的数学物理常数               本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/ ...

  3. [原创].NET 分布式架构开发实战之一 故事起源

    原文:[原创].NET 分布式架构开发实战之一 故事起源 .NET 分布式架构开发实战之一 故事起源 前言:本系列文章主要讲述一个实实在在的项目开发的过程,主要包含:提出问题,解决问题,架构设计和各个 ...

  4. 修改session的存储机制

    <?php  //修改session的存储机制 //最起码应该有一个 读方法, 和一个 写方法. //1, 我们先去建立 读方法 和 写方法. //2, 告知session系统,使用我们的方法完 ...

  5. [leetcode] Combination Sum and Combination SumII

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  6. Vim 基本配置和经常使用的命令

    vim 优势和应用场景 vim 的优点纯文字编辑和 Linux 完美的融合提供了命令行.只能假设 ssh 至server进行操作,那么这样的情况就仅仅能使用 vim 了.vim 也是最为强大的通用文本 ...

  7. Sphinx/Coreseek 4.1 跑 buildconf.sh 一个错误,无法生成configure档

    安装前 coorseek 什么时候,遇到一些错误.该官方网站无法看到的解决方案,终于 google 在大牛的博客评论区找到一个解决方案.突然跑到他的膝盖介绍~~ 这里整理是为了方便一些人发现,墙毕竟让 ...

  8. 按某个字段来分组、编号的row_number()函数

    本文参考 http://zhidao.baidu.com/link?url=8su4F16Et8Q0S3FmybwniJSI51Ms0AeVujcEXhyEaZh3u5LlOng5Xri_9zHsl7 ...

  9. 接口设计ie常见的问题

    问题叙述性说明: 当围绕一个简单的页面布局设计.我发现了一个奇怪的相对布局问题. 同的方式围绕布局接口.它是利用左div浮动.对div设定 margin-left这样达到的效果.实现了chrome浏览 ...

  10. SERVERCONFIG

    -- Create tablecreate table ERP_SERVERCONFIG( id NUMBER not null, servicename VARCHAR2(500), service ...