Moderator: Board moderators
1000 14
500 13
17 1
9 3
147 3
233 11
0 0
CASE 1:
101+101+103+103+107+107+109+109+11+11+113+13+5+7
CASE 2:
101+101+103+103+11+11+13+13+17+17+2+3+5
CASE 3:
17
CASE 4:
No Solution.
CASE 5:
101+17+29
CASE 6:
101+11+11+13+13+17+17+19+19+5+7

route wrote:do you mean that the judge now is still wrong?
#include <iostream.h>
#include <string.h>
int pr[70],kol=0;
char spr[70][5];
void makepr()
{
int i,j;
pr[0]=2;kol++;
for (i=3;i<300;i+=2)
{
int ok=0;
for (j=0;pr[j]*pr[j]<=i;j++)
if (i%pr[j]==0) {ok=1;break;}
if (ok==0) {pr[kol]=i;kol++;}
}
}
int c[70];
void sort(int *pr1,int kol1,int *c)
{
int i,j;
char s1[5];
for (i=0;i<kol1;i++)
{
int h=pr1[i];
int l=0;
c[i]=i;
while (h>0)
{
s1[l]=char(h%10+'0');
h/=10;
l++;
}
s1[l]=0;
for (j=0;j<l;j++)
spr[i][j]=s1[l-j-1];
spr[i][l]=0;
}
for (i=0;i<kol1;i++)
for (j=i+1;j<kol1;j++)
if (strcmp(spr[c[i]],spr[c[j]])>0)
{
int h=c[i];
c[i]=c[j];
c[j]=h;
}
int pr2[70];
memcpy(pr2,pr1,70*sizeof(pr1[0]));
for (i=0;i<kol1;i++)
pr1[i]=pr2[c[i]];
}
int a[1001][15];
int f[1001][15][70];
int q[16000][2],end=0;
int c1[70];
int main()
{
makepr();
sort(pr,kol,c);
int i,j,k,n,t;
for (i=0;i<=1000;i++)
for (j=0;j<15;j++)
{
a[i][j]=-1;
}
a[0][0]=0;
q[0][0]=0;q[0][1]=0;end=1;
for (i=1;i<=61;i++)
{
f[0][0][i]=2;
}
f[0][0][0]=1;
memcpy(c1,f[0][0],70*sizeof(c1[0]));
for (i=0;i<=61;i++)
{
f[0][0][i]=c1[c[i]];
}
while (end>0)
{
i=q[end-1][0],j=q[end-1][1];
int p=0;
for (k=0;k<kol;k++)
if (f[i][j][k]>0)
if (i+pr[k]<1001 && j+1<15)
if (a[i+pr[k]][j+1]==-1)
{
a[i+pr[k]][j+1]=i;
memcpy(f[i+pr[k]][j+1],f[i][j],70*sizeof(f[0][0][0]));
f[i+pr[k]][j+1][k]--;
q[end][0]=i+pr[k];
q[end][1]=j+1;
end++;
p=1;
break;
}
if (p==0) end--;
}
int r=0;
cin>>n>>t;
while (n!=0 && t!=0)
{
r++;
cout<<"CASE "<<r<<":\n";
int ans[15],l=0;
if (a[n][t]==-1) cout<<"No Solution.\n";
else
{
while (n>0)
{
ans[l]=n-a[n][t];l++;
n=a[n][t];t--;
}
sort(ans,l,c1);
cout<<ans[0];
for (i=1;i<l;i++)
cout<<"+"<<ans[i];
cout<<"\n";
}
cin>>n>>t;
}
return 0;
}32 3
47 5
91 4
140 6
199 13
267 11
301 5
444 7
611 9
789 11
921 5
0 0CASE 1:
11+19+2
CASE 2:
11+11+13+5+7
CASE 3:
11+11+2+67
CASE 4:
101+11+11+3+7+7
CASE 5:
11+11+13+13+17+17+19+19+23+3+3+43+7
CASE 6:
101+101+11+11+13+3+3+5+5+7+7
CASE 7:
101+101+11+17+71
CASE 8:
101+101+103+103+11+2+23
CASE 9:
101+101+103+103+107+11+11+13+61
CASE 10:
101+101+103+103+107+107+109+11+11+13+23
CASE 11:
101+101+149+277+293


Users browsing this forum: No registered users and 0 guests