Cod sursa(job #2428504)

Utilizator ageneohasMart Florin ageneohas Data 5 iunie 2019 16:29:53
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.09 kb
/******************************************************************************

                              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;
}