AcWing 3650. 平方和与立方和
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e3 + 10;
int t, n, m, k, l, r, op, x, y;
int pf1[N], lf1[N], pf2[N], lf2[N];
bool flag;
int odd(int x){
if(x%2)return x;
return x-1;
}
int even(int x){
if(x%2)return x-1;
return x;
}
void solve() {
lf1[1]=pf1[1]=1;
for (int i = 2; i < N; i++) {
if (i % 2) {
pf1[i] = i * i;
lf1[i] = pf1[i] * i;
pf1[i] += pf1[i - 2];
lf1[i] += lf1[i - 2];
} else {
pf2[i] = i * i;
lf2[i] = pf2[i] * i;
pf2[i] += pf2[i - 2];
lf2[i] += lf2[i - 2];
}
}
while (cin >> l >> r) {
if(l>r)swap(l,r);
cout<<pf2[even(r)]-pf2[even(l)-(even(l)==l?2:0)]<<" "<<
lf1[odd(r)]-lf1[odd(l)-(odd(l)==l?2:0)]<<"\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}