QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#164109 | #7054. Fibonacci Sequence | wifi32767# | WA | 0ms | 3684kb | C++20 | 1.5kb | 2023-09-04 19:55:00 | 2023-09-04 19:55:00 |
Judging History
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: 0ms
memory: 3684kb
input:
output:
0
result:
wrong answer 1st lines differ - expected: '1 1 2 3 5', found: '0'