Cod sursa(job #2221470)

Utilizator al_k_ponyClaudiu Babin al_k_pony Data 14 iulie 2018 14:05:05
Problema Fractii Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int ans,n,f[1 << 20],b[1 << 20];

int32_t main(){_
    freopen("fractii.in","r",stdin);
    freopen("fractii.out","w",stdout);
    cin >> n;
    for(int i = 1;i <= n;i++) f[i] = i;
    for(int i = 2;i <= n;i++)
    {
    	for(int j = 2 * i;j <= n;j += i)
    	{
    		b[j] = 1;
    		if(!b[i])
    		{
    			f[j] = f[j] - f[j] / i;
    		}
    	}
    	if(!b[i]) f[i]--;
    }
    for(int i = 2;i <= n;i++) ans += f[i];
    ans *= 2;
	ans++;
	rc(ans);
}