Pagini recente » Cod sursa (job #3124265) | Cod sursa (job #1750986) | Cod sursa (job #728712) | Cod sursa (job #2448117) | Cod sursa (job #237053)
Cod sursa(job #237053)
/***************************************************************************
* Copyright (C) 2008 by cata,,, *
* cata@cata-laptop *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
#include<fstream>
#define dim 1000000
using namespace std;
ifstream f("/home/cata/te/src/fractii.in");
ofstream g("/home/cata/te/src/fractii.out");
void prime_ciur(long long n, int v[])
{long long i,j;
for(i=2;i<=n;i++) v[i]=1;
for(i=2;i<=n;i++)
for(j=2*i;j<=n;j=j+i)
v[j]=0;
}
int main(int argc, char *argv[])
{
long long n, b,a,k=0;float nr;
int *v,i;//declararea dinamica a vectorului
v=new int [dim];
f>>n;
prime_ciur(n,v);
for(b=2;b<=n;b++)
{
if(v[b]==1) nr=b-1;
else
{
nr=b;
for(a=2;a*a<=b;a++)
if(b%a==0 && v[a]==1) nr=(1-1.0/a)*nr;
}
k=k+2*nr;
}
g<<k+1;
f.close();
g.close();
delete v;
return EXIT_SUCCESS;
}