joj2201

 2201: Prime and Decompounding


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s 8192K 400 209 Standard
A positive interger except 1 can be decompounded to the sum of several prime numbers(include only one number). For exsample, four of the different forms in essence of the decompounding for 9 are: 9 = 2 + 5 + 2 = 2 + 3 + 2 + 2 = 3 + 3 + 3 = 2 + 7. Here the different forms in essence means that one expression can't be the same with others by exchange numbers in the it. Now do you know how many different decompounding forms in essence for any given number N.

Input and Output

The input will consist several lines, each line is a positive interger N(2 < N <= 330) for which output the anwser in a single line.

Sample Input

2
200

Sample Output

1
9845164


This problem is used for contest: 29 


Submit / Problem List / Status / Discuss



#include <iostream>
#include <stdio.h>
using namespace std;
int prime[350]={0};
long long  c1[350]={0};
long long  c2[350]={0};
int main()
{
    int n=340;
    for(int i=2;i<=n;i++)
    {
        for(int j=2;j*i<=n;j++)
        {
            prime[j*i]=1;
        }
    }
    for(int i=0;i<=n/2;i++)
    {
        c1[i*2]=1;
    }
    for(int i=3;i<n;i++)
    {
        if(prime[i]==0)
        {
            for(int j=0;j<n;j++)
            {
                for(int k=0;k+j<n;k+=i)
                {
                    c2[k+j]+=c1[j];
                }
            }
            for(int i=0;i<=n;i++)
            {
                c1[i]=c2[i];
                c2[i]=0;
            }
        }
    }
    while(scanf("%d",&n)==1)
    {
        cout<<c1[n]<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值