欧拉计划(Project Euler)第十九题 matlab

   日期:2020-09-28     浏览:90    评论:0    
核心提示:欧拉计划(Project Euler)第十九题 matlab原题目: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 al

欧拉计划(Project Euler)第十九题 matlab
原题目:
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日为星期一;
  • 一三五七八十腊是31天,其余除了二月,都是30天;
  • 二月除了闰年都是28天,闰年29天。2000年虽然是世纪年,但是能被400整除,故也是闰年。
    计算范围是1901年一月1日到2000年十二月31日
sum=1;
a=[31 28 31 30 31 30 31 31 30 31 30 31];
b=0;
for year=1901:2000
    for i=1:12
    if mod(year,4)==0
        a(2)=29;
    end
    sum=sum+a(i);
    if mod(sum,7)==5
        b=b+1;
    end
    end
end
b   

最后输出结果是171

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服