This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
int main()
{
int n,a=0,b=0,c=0,k,i,j,t;
scanf("%d",&t);
for(i=1;i<=t;i++){
a=0;b=0;c=0;
scanf("%d",&n);
a=n/3;
k=n%3;
if(k==1){
if(a>=5){a=a-5;c=c+2;k=0;}
else if(a>=3){a=a-3;b=b+2;k=0;}
}
if(k==2){
if(a>=2){c++;a=a-2;k=0;}
else if(a>=1){b++;k=0;a--;}
}
if(a>=8){c=c+(a/8)*3;a=a%8;}
if(a>=5){b=b+(a/5)*3;a=a%5;}
if(b>=8){c=c+(b/8)*5;b=b%8;}
if(a>0 && b>0){
if(a>=b){c=c+b;a=a-b;b=0;}
if(a<b){c=c+a;b=b-a;a=0;}
}
if(a>=4 && c>=1){
a=a-4;
c--;
b=b+4;
}
if(k==0){
for(j=1;j<=a;j++)printf("3");
for(j=1;j<=b;j++)printf("5");
for(j=1;j<=c;j++)printf("8");
}
else printf("-1");
printf("\n");
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |