标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 724 Accepted Submission(s): 404
///1085422276 #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <queue> #include <typeinfo> #include <map> typedef __int64 ll; using namespace std; #define inf 10000000 inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘)f=-1; ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘; ch=getchar(); } return x*f; } int gcd(int a,int b) { if(b==0)return a; return gcd(b,a%b); } //*************************************************************** ll dp[1002][1002]; ll prim[1002]; ll hashs[1002]; ll cnt; ll dfs(ll n,ll p) { if(dp[n][p])return dp[n][p]; if(n<prim[p]) { dp[n][p]=1; return 1; } dp[n][p]=dfs(n,p+1); ll tmp=prim[p]; while(tmp<=n) { dp[n][p]+=dfs(n-tmp,p+1); tmp*=prim[p]; } return dp[n][p]; } int main() {ll n; cnt=0; for(ll i=2;i<=1001;i++) { if(hashs[i]==0) { prim[cnt++]=i; for(ll j=i+i;j<=1000;j+=i)hashs[j]=1; } } memset(dp,0,sizeof(dp)); while(scanf("%I64d",&n)!=EOF){ printf("%I64d\n",dfs(n,0)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4746634.html