【題解】ZeroJudge c777: 106北二2.規律的數列

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=c777

#include <iostream>
using namespace std;

long long n, m, a[100], ans;

int main() {
    cin >> n >> m;
    a[1] = 1;
    a[2] = 2;
    if (n < 3) ans = 3-n;
    for (int i = 3; i < 100; i++){
        a[i] = a[i-3]+a[i-2]+a[i-1];
        if (a[i] > m) break;
        else if (a[i] >= n) ans++;
    }
    cout << ans << "\n";
}
分享本文 Share with friends