Skip to content

Instantly share code, notes, and snippets.

@MinecraftFuns
Created February 11, 2021 05:06
Show Gist options
  • Save MinecraftFuns/53a5c887560d3c4fcf47ade3e1ab15a0 to your computer and use it in GitHub Desktop.
Save MinecraftFuns/53a5c887560d3c4fcf47ade3e1ab15a0 to your computer and use it in GitHub Desktop.
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename Tp>
inline void read(Tp &x)
{
x = 0;
bool neg = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
{
if (c == '-')
{
neg = 1;
}
}
for (; isdigit(c); c = getchar())
{
x = x * 10 + c - '0';
}
if (neg)
{
x = -x;
}
}
template <typename Tp>
inline const Tp gcd(Tp m, Tp n)
{
while (n != 0)
{
Tp t = m % n;
m = n;
n = t;
}
return m;
}
const int P = 1e9 + 7;
int n;
inline int phi(int x)
{
int res = x;
int _x = sqrt(x);
for (int i = 2; i <= _x; i++)
{
if (x % i == 0)
{
res /= i;
res *= i - 1;
do
{
x /= i;
} while (x % i == 0);
}
}
if (x != 1)
{
res /= x;
res *= x - 1;
}
return res;
}
template <typename Tp>
inline int mod(const Tp &x)
{
return (x + P) % P;
}
int main()
{
while (~scanf("%d", &n) && n != 0)
{
int p = phi(n);
int ans = mod((1ll * n * (n - 1) / 2) % P - (1ll * n * p / 2) % P);
printf("%d\n", ans);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment