蓝桥杯练习系统 拿糖果

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int d[10000];
int z[10000][5000];
int zhi(int x)
{
    for(int i=2;i<x;i++)
    {
        if(x%i==0)
        return 0;
    }
    return 1;
}

void f(int n)
{
    for(int i=0;i<=n;i++)
    {
        if(zhi(i))
        d[i]=0;
        else
        {
            for(int j=2;j<=sqrt(i);j++)
            {   
                int t;
                if(i%j==0&&zhi(j))
                {
                    t=d[i-2*j]+j;
                    if(t>d[i])
                        d[i]=t;
                }

            }
        }
    }

}
int main()
{
    int n;
    scanf("%d",&n);
    f(n);
    printf("%d",d[n]);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Boom_1/article/details/71222346