/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 61ms 8.188 MiB
#2 Accepted 64ms 8.02 MiB
#3 Accepted 361ms 8.047 MiB
#4 Accepted 357ms 8.215 MiB
#5 Accepted 362ms 8.211 MiB
#6 Accepted 162ms 8.188 MiB
#7 Accepted 364ms 8.211 MiB

Code

/*
	JAI JAGANNATH!
*/
//@Author : zanj0

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;


#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define endl "\n"
#define timetaken cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC << "ms\n"

typedef long long int lli;

void zanj0()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
}
const lli N = 1e6 + 5;
lli cnt[N];
void Pre()
{
	lli i, j;
	for (i = 1; i < N; i++)
	{
		for (j = i; j < N; j += i)
		{
			cnt[j]++;
		}
	}
	for (i = 1; i < N; i++)
		cnt[i] += cnt[i - 1];
}
lli HarmonicSum(lli x){
	lli ret = 0;
	lli i;
	for(i = 1; i * i <= x; i++){
		ret += x / i;
	}
	ret *= 2;
	i--;
	ret -= i * i;
	ret -= x;
	return ret;
}
void Solve()
{
	lli n;
	cin >> n;
	cout << HarmonicSum(n) << endl;
}
int32_t main()
{
	zanj0();
	Pre();
	w(t) Solve();
	timetaken;
	return 0;
}

/*
Number of pairs (i, j) such that j - i = gcd(i, j)
Let's say gcd(i, j) is g then (j % g) - (i % g) == 0

i = k * g
j = (k + 1) * g


k and (k + 1) will be co-prime
That means for g the pairs will be N / g - 1
*/

Information

Submit By
Type
Submission
Problem
P1207 D2. GCD equal Absolute Value (Hard Version)
Language
C++17 (G++ 13.2.0)
Submit At
2025-08-02 19:45:09
Judged At
2025-08-02 19:45:09
Judged By
Score
100
Total Time
364ms
Peak Memory
8.215 MiB