洛谷——P1832 A+B Problem(再升级)

https://www.luogu.org/problem/show?pid=1832#sub

题目背景

·题目名称是吸引你点进来的

·实际上该题还是很水的

题目描述

·1+1=? 显然是2

·a+b=? 1001回看不谢

·哥德巴赫猜想 似乎已呈泛滥趋势

·以上纯属个人吐槽

·给定一个正整数n,求将其分解成若干个素数之和的方案总数。

输入输出格式

输入格式:

 

一行:一个正整数n

 

输出格式:

 

一行:一个整数表示方案总数

 

输入输出样例

输入样例#1:
7
输出样例#1:
3

说明

【样例解释】

7=7 7=2+5

7=2+2+3

【福利数据】

【输入】 20

【输出】 26

【数据范围及约定】

对于30%的数据 1<=n<=10

对于100%的数据,1<=n<=10^3

 

*long long*

 1 #include <algorithm>
 2 #include <iostream>
 3 
 4 #define LL long long
 5 #define N 1015 
 6 
 7 using namespace std;
 8 
 9 LL n,cnt;
10 bool if_break;
11 LL prime[N];
12 LL f[N*10];
13 
14 bool ok(LL x)
15 {
16     if(x==1) return false;
17     for(int i=2;i*i<=x;i++)
18         if(x%i==0) return false;
19     return true;
20 }
21 
22 int main()
23 {
24     cin>>n;
25     for(int i=1;i<=n;i++)
26         if(ok(i)) prime[++cnt]=i;
27     f[0]=1;
28     for(int i=1;i<=cnt;i++)
29         for(int j=prime[i];j<=n;j++)
30             f[j]+=f[j-prime[i]];
31     cout<<f[n];
32     return 0;
33 }

 

posted @ 2017-04-22 14:55  Aptal丶  阅读(414)  评论(0编辑  收藏  举报