Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define f first
- #define s second
- #define pb push_back
- #define mp make_pair
- #define ll long long
- #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- using namespace std;
- const int INF = 1e9 + 1;
- const int MOD = 1e9 + 7;
- const int MAXN = 1e6 + 10;
- int cnt[MAXN], a[MAXN], s[MAXN], kk[MAXN];
- int min_div[MAXN + 10];
- ll dp[MAXN + 10], phi[MAXN + 10];
- void solve(){
- ll n;
- cin >> n;
- cout << 1LL * n * (n - 1) / 2 - dp[n] << "\n";
- }
- int main() {
- IOS;
- for (int i = 2; i <= MAXN; i++){
- if (min_div[i] == 0){
- min_div[i] = i;
- for (ll j = 1LL * i * i; j <= MAXN; j += i){
- if (min_div[j] == 0){
- min_div[j] = i;
- }
- }
- }
- }
- phi[1] = 0;
- dp[1] = 0;
- for (int i = 2; i <= MAXN; i++){
- if (min_div[i] == i){
- phi[i] = i - 1;
- }
- else{
- int x = i;
- int y = 1;
- while(x % min_div[i] == 0){
- x /= min_div[i];
- y *= min_div[i];
- }
- if (x == 1){
- phi[i] = i - i / min_div[i];
- }
- else{
- phi[i] = phi[x] * phi[y];
- }
- }
- dp[i] = dp[i - 1] + phi[i];
- }
- int t = 1;
- // cin >> t;
- while(t--){
- solve();
- }
- return 0;
- }
- //phi[120] = phi[2 ^ 3] * phi[3] * phi[5]
Advertisement
Add Comment
Please, Sign In to add comment