Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 06:33
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/397ef221d725b3ae764fea31b41cb514 to your computer and use it in GitHub Desktop.
Save completejavascript/397ef221d725b3ae764fea31b41cb514 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
#define ull unsigned long long
const int LARGE = 1000000007;
/*
* Tổng các số từ start đến end công sai d = 1
*/
ull Sum(ull start, ull end)
{
ull num = end - start + 1;
return num * (start + end) / 2;
}
int main()
{
//freopen("input.txt","r",stdin);
int T;
cin >> T;
for(int tc = 0; tc < T; tc++)
{
// Nhập đầu vào
ull N;
cin >> N;
ull answer = 0, k;
// Tính toán bình thường với số chia
// từ 1 đến căn bậc hai của N
for(k = 1; k*k <= N; k++)
answer += k * (N / k);
// Từ đây giá trị thương số của N / x sẽ bị lặp lại
// Các bạn chịu khó viết thử một vài trường hợp ra
// sẽ thấy quy luật.
ull x = k - 1;
for(ull i = N / x; i > 1; i--)
{
ull y = N / (i-1);
answer += Sum(x+1,y) * (i-1);
x = y;
}
cout << answer % LARGE << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment