Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/f2e88ca80ec0490d8d710bcf7f5abc3a to your computer and use it in GitHub Desktop.
Save completejavascript/f2e88ca80ec0490d8d710bcf7f5abc3a to your computer and use it in GitHub Desktop.
#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