QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164105#7054. Fibonacci Sequencewifi32767#WA 1ms3388kbC++201.5kb2023-09-04 19:53:472023-09-04 19:53:48

Judging History

你现在查看的是最新测评结果

  • [2023-09-04 19:53:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3388kb
  • [2023-09-04 19:53:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX = 1e3 + 10, mod = 998244353;

ll n, k;
ll ans = 0;
ll power(ll x, int y){
    ll ans = 1;
    while (y){
        if (y & 1) ans *= x, ans %= mod;
        x *= x, x %= mod;
        y >>= 1;
    }
    return ans;
}
ll safe_sqrt(ll x){
    ll lk = 0, rk = 2 * sqrt(x);
    while (lk < rk){
        ll mid = (lk + rk) >> 1;
        if (mid * mid >= x) rk = mid;
        else lk = mid + 1;
    }
    return lk;
}
ll cal(ll x){
    ll x1 = (1 + x) * x % mod * power(2,mod - 2) % mod * (n % mod + 1) % mod;
    ll x2 = x * (1 + x) % mod * (2 * x % mod + 1) % mod * power(6,mod - 2) % mod;
    return (x1 - x2 + mod) % mod;
}
void solve(){
    cin >> n;
    k = safe_sqrt(n);
    for (int i = 2; i <= k; ++ i){
        ll t = i - 1;
        int cnt = 1;
        while (t < n){
            ll m = (t + 1) * i - 1;
            if (m > n) ans = (ans + i * cnt % mod * (n - t) % mod) % mod;
            else ans = (ans + i * cnt % mod * (m - t) % mod) % mod;
            t = m;
            cnt ++;
        }
    }
    //ans = (ans + (n + 1) * (n + k + 1) % mod * (n - k) / 2) % mod;
    ans += mod - cal(k % mod) + cal(n % mod);
    cout << ans % mod << endl;
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //cout << fixed << setprecision(20);
    //while (cin >> n)
    //int _;cin>>_;while(_--)
    	solve();
    //did();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3388kb

input:



output:

0

result:

wrong answer 1st lines differ - expected: '1 1 2 3 5', found: '0'