Day2-T3
Describe:质数问题
code:
#pragma GCC optimize(2) #include<bits/stdc++.h> #define KKK 1200 using namespace std; int lasts,n,m,prime[10015],tot,ans; int maxn,sum[KKK],f[KKK][20]; bool b[KKK]; inline void work(int x){ for(int i=1;i<=tot&&prime[i]<=sqrt(x);i++) if(x%prime[i]==0)return;prime[++tot]=x;b[x]=1; } inline int read(){ int ret=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();} while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar(); return ret*f; } inline void write(int x){ if(x<0){putchar('-');write(-x);return;} if(x/10) write(x/10); putchar(x%10+'0'); } int main(){ // freopen("sum.out","w",stdout); prime[++tot]=2;f[0][0]=1; for(register int i=4;i<=KKK;i+=2)b[i]=1; for(register int i=3;i<=KKK;i+=2)work(i); //打表质数 for(register int i=1;i<=tot;i++){ for(register int j=1200;j>=prime[i];j--){ for(register int k=15;k>=1;k--){ f[j][k]+=f[j-prime[i]][k-1]; //从上一个质数跳转 } } } n=read(),m=read(); while(n&&m){ write(f[n][m]); puts(""); n=read(),m=read(); } return 0; }