码迷,mamicode.com
首页 > 其他好文 > 详细

[Luogu P2563]质数和分解

时间:2019-03-23 10:39:24      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:ble   algorithm   return   problem   ring   blank   get   size   +=   

题目链接

话不多说,这是一道质数题+完全背包。先预处理筛出质数,直接背包就行。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int pr[205],tot,x,f[205];
bool vis[205];
int main(){
for(int i=2;i<=200;++i){
    if(!vis[i]){
        pr[++tot]=i;
        for(int j=i+i;j<=200;j+=i)vis[j]=1;
    }
}
while(cin>>x){
    memset(f,0,sizeof(f));f[0]=1;
    for(int i=1;i<=tot&&pr[i]<=x;++i){
        for(int k=pr[i];k<=200;++k)f[k]+=f[k-pr[i]];
    }
    cout<<f[x]<<endl;
}
return 0;
}

 

[Luogu P2563]质数和分解

标签:ble   algorithm   return   problem   ring   blank   get   size   +=   

原文地址:https://www.cnblogs.com/clockwhite/p/10582609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!