Pagini recente » Borderou de evaluare (job #1330306) | Cod sursa (job #434031) | Cod sursa (job #2709387) | Rating Stancu Petre (stancupetre1988) | Cod sursa (job #2428499)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include<fstream>
#include<vector>
#include<math.h>
#include <chrono>
using namespace std::chrono;
using namespace std;
int main()
{
auto start = high_resolution_clock::now();
long long n;
int * v = new int[1000001];
int * nrPrimeIndex = new int [1000001];
int * altVector = new int [1000001];
int count=0;
long long numere=0;
ifstream f("fractii.in");
ofstream g("fractii.out");
f>>n;
for(long i=2;i<=n;++i)
{
if(v[i]==0)
{
nrPrimeIndex[count]=i;
numere=numere+(i-1);
altVector[i]=(i-1);
++count;
for(long long j=i*i;j<=n;j+=i)
v[j]=1;
}
else
{
int o=0;
while(1)
{
if(i%nrPrimeIndex[o]==0)
{
if(v[i/nrPrimeIndex[o]]==0)
{
altVector[i]=nrPrimeIndex[o]*altVector[i/nrPrimeIndex[o]];
}
else
{
altVector[i]=altVector[nrPrimeIndex[o]]*altVector[i/nrPrimeIndex[o]];
}
numere=numere+altVector[i];
break;
}
else
{
o++;
}
}
}
}
if(n>5)
numere=numere*2+3;
else
numere=numere*2+1;
g<<numere;
f.close();
g.close();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout << "Time in seconds:"<<duration.count()/1000000. << endl;
return 0;
}