從1970到指定年份有多少個閏年 快速演算法

2021-06-08 09:34:12 字數 557 閱讀 6642

/*

* number of leap years from 1970 up to, butnot including, the specified year

* (expressed as the number of years since1900).

*/#define

_elapsed_leap_years(y)  (((y - 1)/4) - ((y- 1)/100) + ((y + 299)/400) \

- _leap_year_adjust)

[1900,x) y=x-1900表示從[1900,x-1]一共有y年

((y -1)/4)表示這y年一共有多少能被4整除的數,除去第乙個

((y -1)/100)表示這y年一共有多少能被100整除的數,除去第乙個

((y +299)/400)表示一共有多少能被400整除的數

(y-101+400)/400

[1900,2000]共有101年

_leap_year_adjust

為從1900-1970

,一共有

17個閏年

從 0,0 到(m,n)有多少種路徑,棋盤問題

include stdafx.h include include include define max 1000 int path max 2 int m,n using namespace std 路徑輸出 void print path int index 搜尋演算法 遞迴的思想,當前路徑要麼向...

Git push 從本地指定分支到遠端指定分支

有時需要將指定的本地分支強制push到遠端分支,可以在以下命令基礎上加 f,強制執行。git push origin dev master meaning git pushto remoteorigin masterfrom localdev 以上命令的含義是push 到遠端origin的maste...

自然數從1到n之間,有多少個數字含有1

問題明確而簡單.for迴圈肯定是不好的.用遞推方法 定義h n 從1到9999.9999 n 個 9 之間含有1的數字的個數.定義f n 為n位數中含有1的數字的個數.由定義可知 h n f 1 f 2 f 3 f n 則f 1 h 1 1 f 2 10 1 8 h 1 f 3 10 2 8 h 2...