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


题意:在二十世纪(1901年1月1日到2000年12月31日)中,有多少个月的1号是星期天?

蔡勒公式:计算 ( year , month , day ) 是星期几

以下图片仅供学习!
o_%e7%81%ab%e7%8b%90%e6%88%aa%e5%9b%be_2017-06-30T08-18-57.072Z.png


/*************************************************************************
    > File Name: euler019.c
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年06月30日 星期五 15时58分37秒
 ************************************************************************/

#include <stdio.h>
#include <math.h>
#include <inttypes.h>

int32_t CountingSundays(int32_t y , int32_t m , int32_t d) {    // 蔡勒公式
    if (m == 1 || m == 2)   m += 12 , y--;
    int32_t w;
    w = (d + 2 * m + 3 * (m + 1) / 5 + y + (int32_t)floor(y/4) - (int32_t)floor(y/100) + (int32_t)floor(y/400)) % 7;
    return w;
}
int32_t main() {
    int32_t ans = 0;
    for (int32_t y = 1901 ; y <= 2000 ; y++) {
        for (int32_t m = 1 ; m <= 12 ; m++) {
            if (CountingSundays(y , m , 1) != 6)    continue;
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

转载于:https://www.cnblogs.com/WArobot/p/7099463.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值