Pagini recente » Cod sursa (job #816093) | Cod sursa (job #194004) | Cod sursa (job #105948) | Cod sursa (job #581057) | Cod sursa (job #971050)
Cod sursa(job #971050)
#include <cstdio>
#include <vector>
#include <cmath>
int main(void)
{
freopen("fractii.in", "r", stdin);
freopen("fractii.out", "w", stdout);
int nV = 0, nS = 0, nC = 0;
scanf("%d", &nV);
std::vector<int> myV;
std::vector<bool> myB;
myB.resize(nV + 1, true);
for(int i(2); i <= sqrt(nV); i++)
if(myB[i])
for(int j(i * i); j <= nV; j += i)
myB[j] = false;
myB.clear();
for(int i(2); i <= nV; i++)
if(myB[i])
{
nS++;
myV.push_back(i);
}
bool **hash = new bool*[nV + 1];
for(int i(0); i <= nV; i++)
hash[i] = new bool[nV + 1];
for(int i(0); i <= nV; i++)
for(int j(0); j <= nV; j++)
hash[i][j] = false;
for(int i(0); i < nS; i++)
{
int j = myV[i];
while(j < nV + 1)
{
hash[myV[i]][j] = true;
j += myV[i] ;
}
}
nC = (nV - 1) * 2 + 1;
for(int i(0); i < nS; i++)
for(int j(0); j <= nV; j++)
if(hash[myV[i]][j])
for(int k(i + 1); k < nS; k++)
hash[myV[k]][j] = false;
for(int i(0); i < nS; i++)
for(int j(0); j <= nV; j ++)
if(hash[myV[i]][j])
for(int k(i + 1); k < nS; k++)
for(int l(0); l <= nV; l++)
if(hash[myV[k]][l] && j % myV[k] != 0) nC += 2;
printf("%d ", nC);
return 0;
}