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. [LeetCode129]Sum Root to Leaf Numbers

    题目: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a nu ...

  2. 同台电脑部署多组Tomcat负载均衡(或集群)

    可能这种需求比较少见,不过如果手上服务器不够用.可以考虑先这么干着.. 具体Tomcat怎么搭集群,就不在这细说了.只写同台电脑部署多组集群需要修改和注意的地方. 一.Apache 先是Apache, ...

  3. BackGroundWorker使用总结

    方法: backgroundWorker1.CancelAsync() 用于取消异步执行 backgroundWorker1.ReportProgress(int ,object)用于向主线层报告进度 ...

  4. java: org.luaj.vm2.LuaError:XXX module not found lua脚本初始化出错(转)

    我遇到这个错误是因为在引用脚本目录时,设置错了位置.设置成脚本所在目录的上级目录. lua使用和加载初始化方法 在java中使用lua,使用需要引用 luaj-jse-2.0.2.jar 同时需要使用 ...

  5. ListView滑动删除 ,仿腾讯QQ

    转载请表明出处:http://blog.csdn.net/lmj623565791/article/details/22961279 在CSDN上开了很多大神们的文章,感觉受益良多,也非常欣赏大家的分 ...

  6. hdu 4864 Task (馋)

    # include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...

  7. 非常基本的SQL 内外连接

    有些问题一直很郁闷,例如:为什么会存在大约在同一时间连接这个东西.如果外键为空,创建问题的声明时,将有一个外键约束失败. 后来,在精心研究,恩.外部连接(左连接.正确的连接). 事实上都是非常基础的东 ...

  8. javascript动画中的“帧”

    在写游戏的时候,动画移动的速度需要保持一致,为了在各个软硬件环境中速度的一致,需要考虑帧频的不同. 计算时间系数: 时间系数 = 目标FPS / 实际FPS 计算实际FPS actualFPS = 1 ...

  9. 文件搜索神器 Everything

    Everything 是一款 NTFS 磁盘格式下的文件搜索工具,1月5日发布测试版本 1.3.0.631b Beta,增加文件列表.收藏夹.自定义快捷键.高级搜索等功能,取消了比较实用的 etp/f ...

  10. C#托付和事件

    C#托付.我看了非常长时间的资料和帖子, 曾经对托付的理解就是托付事实上就是将一个方法作为參数传递给第一个方法. 如今对托付的认识则变了一些的,托付能够实现: 1.在两个不能直接调用的方法之间做为桥梁 ...