a059. 完全平方和 - 高中生程式解題系統
本文最後更新於:2024年1月12日 下午
Zerojudge
解題紀錄
a059. 完全平方和 - 高中生程式解題系統
// Author : ysh
// 07/04/2022 Mon 16:56:48.46
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<int>f;
for(int i = 1;i<1000;i++) {
f.push_back(i * i);
}
map<int,int>m;
int last = 0;
m.insert({-1,0});
for(int i : f) {
m.insert({i,last + i});
last = last + i;
}
int n;cin>>n;
for(int i = 0;i<n;i++) {
int a,b;cin>>a>>b;
int sig = prev(m.upper_bound(b))->second - prev(m.lower_bound(a))->second;
cout<<"Case "<<i + 1<<": "<<sig<<"\n";
}
return 0;
}
a059. 完全平方和 - 高中生程式解題系統
http://mysh212.github.io/algosolution/Zerojudge-a059-2.cpp/