Pagini recente » Cod sursa (job #1205091) | Cod sursa (job #434030) | Cod sursa (job #1184155) | Rating Buzea Luca (Snow8347) | Cod sursa (job #2428466)
/******************************************************************************
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 * nrPrime= 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 long i=2;i<=n;i+=1)
{
if(v[i]==0)
{
nrPrime[i]=1;
nrPrimeIndex[count]=i;
numere=numere+(i-1);
count++;
v[i]=1;
for(long long j=i*i;j<=n;j+=i)
v[j]=1;
}
else
{
int copie=i;
int o=0;
int k=0;
while(copie>1)
{
if(copie%nrPrimeIndex[o]==0)
while(copie%nrPrimeIndex[o]==0)
{
altVector[nrPrimeIndex[o]]++;
copie=copie/nrPrimeIndex[o];
}
o++;
}
long long produs=1;
for(int parcurgere=2;parcurgere<=nrPrimeIndex[o];parcurgere++)
{
if(altVector[parcurgere]>0)
{
produs=produs*((parcurgere-1)*(pow(parcurgere,altVector[parcurgere]-1)));
altVector[parcurgere]=0;
}
}
numere=numere+produs;
}
}
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;
}