Created
September 15, 2018 02:53
-
-
Save completejavascript/f2e88ca80ec0490d8d710bcf7f5abc3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
typedef unsigned long long ull; | |
const ull MAX = 1000005; | |
ull a[MAX]; // Lưu mảng a | |
ull f[MAX]; // Lưu mảng f | |
void CreateArray() | |
{ | |
for(ull i = 0; i < MAX; i++) | |
a[i] = f[i] = 0; | |
// Tạo mảng f | |
for(ull k = 1; k < MAX; k++) | |
{ | |
// Cập nhật cho tất cả các số j có ước số là k | |
for(ull j = k*2; j < MAX; j += k) | |
f[j] += k; | |
} | |
// Tạo mảng a | |
for(ull i = 2; i < MAX; i++) | |
a[i] = a[i-1] + f[i]; | |
} | |
int main() | |
{ | |
ios::sync_with_stdio(false); | |
// comment dòng này trước khi submit | |
freopen("input.txt","r",stdin); | |
CreateArray(); | |
ull T; | |
cin >> T; | |
for(ull tc = 0; tc < T; tc++) | |
{ | |
ull n; | |
cin >> n; | |
cout << a[n] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment