1. 高斯日记

大数学家高斯有个好习惯:无论如何都要记日记。

他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210

后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?

高斯出生于:1777年4月30日。

在高斯发现的一个重要定理的日记上标注着:5343,因此可算出那天是:1791年12月15日。

高斯获得博士学位的那天日记上标着:8113

请你算出高斯获得博士学位的年月日。

提交答案的格式是:yyyy-mm-dd, 例如:1980-03-21

请严格按照格式,通过浏览器提交答案。
注意:只提交这个日期,不要写其它附加内容,比如:说明性的文字。

答案:1799-07-16

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
const ll mod = 1000000007;
double eps = 1e-8;

int mth[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

bool judge(int y){
    return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}

int main(){
    int y = 1777,m = 4,d = 30;
    for(int i = 1;i<=8112;i++){
        d++;
        if(judge(y)) mth[2] = 29; //考虑闰年的情况,改变第2月第天数
        else mth[2] = 28;
        if(d>mth[m]){
            d = 1;
            m++;
            if(m>12){
                m = 1;
                y++;
            }
        }
    }
    printf("%4d-%02d-%02d\n",y,m,d);
    return 0;
}

2. 马虎的算式

小明是个急性子,上小学的时候经常把老师写在黑板上的题目抄错了。

有一次,老师出的题目是:36 x 495 = ?

他却给抄成了:396 x 45 = ?

但结果却很戏剧性,他的答案竟然是对的!!

因为 36 * 495 = 396 * 45 = 17820

类似这样的巧合情况可能还有很多,比如:27 * 594 = 297 * 54

假设 a b c d e 代表1~9不同的5个数字(注意是各不相同的数字,且不含0)

能满足形如: ab * cde = adb * ce 这样的算式一共有多少种呢?

请你利用计算机的优势寻找所有的可能,并回答不同算式的种类数。

满足乘法交换律的算式计为不同的种类,所以答案肯定是个偶数。

答案直接通过浏览器提交。
注意:只提交一个表示最终统计种类数的数字,不要提交解答过程或其它多余的内容。

答案:142

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;

bool vis[11];
int a[6];
int cnt = 0;
void dfs(int now){
    if(now>5){
        int ab = a[1]*10 + a[2];
        int cde = a[3]*100 + a[4]*10+ a[5];
        int adb = a[1]*100 + a[4]*10 + a[2];
        int ce = a[3]*10+a[5];
        if(ab*cde == adb*ce){
            cnt++;
//            cout<<ab<<" * "<<cde<<" = "<<adb<<" * "<<ce<<endl;
        }
    }else{
        for(int i = 1;i<=9;i++){
            if(vis[i]) continue;
            vis[i] = true;
            a[now] = i;
            dfs(now+1);
            vis[i] = false;
        }
    }
}
int main(){
    dfs(1);
    cout<<cnt<<endl;

    return 0;
}

3.第39级台阶

小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级!

站在台阶前,他突然又想着一个问题:

如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢?

请你利用计算机的优势,帮助小明寻找答案。

要求提交的是一个整数。
注意:不要提交解答过程,或其它的辅助说明文字。

答案:51167078

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;

int dp[maxn][2];
int main(){
    dp[0][0] = 1,dp[0][1] = 0;
    dp[1][0] = 0,dp[1][1] = 1;
    for(int i =2;i<=39;i++){
        dp[i][0] = dp[i-1][1] + dp[i-2][1];
        dp[i][1] = dp[i-1][0] + dp[i-2][0];
    }
    cout<<dp[39][0]<<endl;
    return 0;
}

4 黄金连分数

黄金分割数0.61803... 是个无理数,这个常数十分重要,在许多工程问题中会出现。有时需要把这个数字求得很精确。
对于某些精密工程,常数的精度很重要。也许你听说过哈勃太空望远镜,它首次升空后就发现了一处人工加工错误,对那样一个庞然大物,其实只是镜面加工时有比头发丝还细许多倍的一处错误而已,却使它成了“近视眼”!!
言归正传,我们如何求得黄金分割数的尽可能精确的值呢?有许多方法。
比较简单的一种是用连分数:
1
黄金数 = ---------------------
1
1 + -----------------
1
1 + -------------
1
1 + ---------
1 + ...
这个连分数计算的“层数”越多,它的值越接近黄金分割数。
请你利用这一特性,求出黄金分割数的足够精确值,要求四舍五入到小数点后100位。
小数点后3位的值为:0.618
小数点后4位的值为:0.6180
小数点后5位的值为:0.61803
小数点后7位的值为:0.6180340
(注意尾部的0,不能忽略)
你的任务是:写出精确到小数点后100位精度的黄金分割值。
注意:尾数的四舍五入! 尾数是0也要保留!

显然答案是一个小数,其小数点后有100位数字。
答案:
0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll maxn = 1e6+10;
double eps = 1e-8;

bool cmp(string a,string b){
    int idx1 = a.find_first_not_of('0'),idx2 = b.find_first_not_of('0');
    a = idx1!=-1? a.substr(idx1) : "0";
    b = idx2!=-1? b.substr(idx2) : "0";
    if(a.size() != b.size()) return a.size() >= b.size();
    return a>=b;
}

string add(string a,string b){
    if(a.size() > b.size()) swap(a,b);
    b.insert(b.begin(),'0');
    int t = 0;
    for(int i = b.size()-1,j = a.size()-1;i>=0;i--,j--){
        int cur;
        if(j>=0) cur = (a[j]-'0') + (b[i]-'0') + t;
        else cur = (b[i] - '0') +t;
        b[i] = (cur%10) + '0';
        t = cur/10;
    }
    int idx = b.find_first_not_of('0');
    return idx != -1? b.substr(idx): "0";
}

string sub(string a,string b){
    //a大b小
    int t = 0;
    for(int i = a.size()-1,j = b.size()-1;i>=0;i--,j--){
        int up = 0,down = 0;
        up = (a[i]-'0') + t; t = 0;
        if(j>=0) down = (b[j]-'0');
        if(up < down) up+=10,t = -1;
        int cur = up-down;
        a[i] = cur+'0';
    }
    int idx = a.find_first_not_of('0');
    return idx != -1? a.substr(idx) : "0";
}

// 用减法代替除法
string divbb(string a,string b,int len){
    string c = "";int tag = 1;
    for(int i = 1;i<=len;i++){
        int cnt = 0;
        while(cmp(a,b)){
            cnt++;
            a = sub(a,b);
        }
        c += to_string(cnt);
        if(tag) c+='.';tag = 0;
        a += '0';
    }
    return c;
}


int main(){
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    string a = "1",b = "2";
    for(int i = 3;i<=400;i++){
        string c = add(a,b);
        a = b,b =c;
    }
    string c = divbb(a,b,102);//整数一位,小数点后保留101位
    return 0;
}
//输出:
//0.6180339887498948482045868343656381177203091
// 79805762862135448622705260462818902449707207
// 20418939113748