Pagini recente » Borderou de evaluare (job #1569050) | Cod sursa (job #942863) | Cod sursa (job #1688222) | Cod sursa (job #1117675) | Cod sursa (job #24823)
Cod sursa(job #24823)
// 60 pcte
#include <stdio.h>
#include <fstream.h>
#include <string.h>
int maxim, v;
long long int val;
int ok[1000001], tot[1000001], p = 0, t;
int Cmmdc( int a, int b )
{
int k = 0;
if ( a == 0 ) return b;
if ( b == 0 ) return a;
while ( (a&1) == 0 && (b&1) == 0 )
{
a >>= 1;
b >>= 1;
k++;
}
while ( a != b )//cel putin unul este impar
{
if ( (a&1) == 0 )
{
a >>= 1;
}
else if ( (b&1) == 0 )
{
b >>= 1;
}
//amandoua impare
else if ( a > b )
{
a = (a-b) >> 1;
}
else b = (b-a) >> 1;//diferenta lor este un numar par
}
return a << k;
}
int main()
{
freopen("fractii.in","r",stdin);
freopen("fractii.out","w",stdout);
scanf("%d", &t);
tot[2] = 1;
tot[3] = 2;
int j;
for ( int n = 2; n <= t; n++ )
{
if ( tot[n] == 0 )
{
int i;
int p = 0;
for ( i = 2; i*i <= n; i++ )
{
if ( n % i == 0 )
{
j = 1;
while ( i*j <= t )
{
if( ok[i*j] == 0 && i*j <= n ) p++;
if ( i*j <= n ) ok[i*j] = 1;
if ( tot[n] != 0 && tot[i] != 0 ) tot[n*i] = tot[n]*tot[i];
if ( Cmmdc(i,j) == 1 && tot[j] != 0 && tot[i] != 0 )
{
tot[i*j] = tot[i]*tot[j];
if ( tot[n] != 0 ) tot[i*j*n] = tot[n*i*j];
}
j++;
}
}
}
if ( p == 0 ) tot[n] = n - 1;
if ( tot[n] == 0 ) tot[n] = n - p;
if ( n < t ) memset(ok, 0, n*sizeof(ok[0]));
}
val += tot[n];
}
val <<= 1;
val += 1;
printf("%lld",val);
}