Pagini recente » Cod sursa (job #2455681) | Cod sursa (job #675088) | Cod sursa (job #3256747) | Cod sursa (job #1498462) | Cod sursa (job #140208)
Cod sursa(job #140208)
#include <fstream.h>
#include <math.h>
ifstream f("fractii.in");
ofstream g("fractii.out");
long long prod,i,p,s,n,j,k,n_aux,nprime;
char prime[1000000];
char marc[1000000];
int main(){
// f>>n;
//n=10000;
f>>n;
s=0;
s+=n;
// s+=n+1+2+2+4;
for(j=0;j<n+1;j++)prime[j]='0';
for(j=0;j<n+1;j++)marc[j]='0';
prime[n+1]='\0';
for (j=2;j<n;j++)
if (prime[j]=='0'){
k=1;
while(k<n){
prime[j*(++k)]='1';
}
}
for (i=2;i<=n;i++)
{ nprime=1;
if (prime[i]=='0')s+=(n-n/i);
else{
for(j=2;j<=n/2;j++)
if (prime[j]=='0' && i%j==0)
for (k=j;k<=n;k+=j) marc[k]='1';
for (j=2;j<=n;j++)
if (marc[j]=='0')nprime++;
else marc[j]='0';
s+=nprime;}
}
g<<s;
f.close();
g.close();
return 0;
}