/*
问题描述
妈妈给小B买了N块糖!但是她不允许小B直接吃掉。
假设当前有M块糖,小B每次可以拿P块糖,其中P是M的一个不大于根号下M的质因数。这时,妈妈就会在小B拿了P块糖以后再从糖堆里拿走P块糖。
然后小B就可以接着拿糖。
现在小B希望知道最多可以拿多少糖。
输入格式
一个整数N
输出格式5
最多可以拿多少糖
样例输入
15
样例输出
6
数据规模和约定
N <= 100000
*/
#include <stdio.h>
#include <stdbool.h>
int q_ds(int);
bool shi_zs( int );
void chushihua(int [],int ,int);
int main(void)
{
int n ;
scanf("%d" , & n ) ;
printf("%d\n",q_ds(n));
return 0;
}
void chushihua(int a[],int n,int x)
{
while ( n -- > 0 )
{
* a ++ = x ;
}
}
bool shi_zs( int n )
{
int i ;
for ( i = 2 ; i * i <= n ; i ++ )
{
if ( n % i == 0 )
{
return false ;
}
}
return true ;
}
int q_ds(int n)
{
int zdts[n+1] ;
chushihua(zdts,n+1,0);
int i ;
for ( i = 2 + 2 ; i < n + 1 ; i ++ )
{
int p ;
for ( p = 2 ; p * p <= i ; p ++ )
{
if ( i % p == 0 )
{
if ( shi_zs( p ) )
{
if ( p + zdts[ i - p - p ] > zdts[ i ] )
{
zdts[ i ] = p + zdts[ i - p - p ];
}
}
}
}
}
return zdts[n];
}