Pagini recente » Cod sursa (job #322176) | Cod sursa (job #1644796) | Cod sursa (job #1874786) | Cod sursa (job #610366) | Cod sursa (job #1427785)
#include <fstream>
#include <cstring>
#include <vector>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0)
return (a == 1) ? 0 : a;
return gcd(b, a % b);
}
int main() {
ifstream fi("fractii.in");
ofstream fo("fractii.out");
long long n;
fi >> n;
vector<bool> sieve(n + 1);
memset(sieve, 0, n + 1);
sieve[2] = true;
long long ans = n * n - (n - 1);
for (long i = 2; i <= n; i++)
if (sieve[i]) {
for (long j = i * i; j <= n; j += i)
sieve[j] = false;
long aux = n / i;
ans -= aux * (aux - 1);
}
fo << ans;
return 0;
}