ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

What's wrong with this code??
Posted by Petar Zhivkov Petrov 20 Apr 2001 21:10
#include <stdio.h>
unsigned long N;
int ind;
char buf[51];
int main()
{
    int i,n;
    scanf("%lu",&N);
    if (N<10) {
        if (N!=0) printf("%lu\n",N);
        else printf("1\n");
        return 0;
        }
    buf[49]=0;
    ind=48;
    for (;;) {
        n=1;
        for (i=9;i>=2;i--) if (N%i==0) {
            n=0;N/=i;buf[ind--]=i+'0';break;
            }
        if (N==1) break;
        if (n) {
            printf("1\n");
            return 0;
            }
        }
    printf("%s\n",buf+ind+1);
    return 0;
}
Re: What's wrong with this code??
Posted by Nazar Revutsky 20 Apr 2001 22:41
>     if (N<10) {
>         if (N!=0) printf("%lu\n",N);
>         else printf("1\n");
>         return 0;
>         }

if(N==0)
printf("10\n");
   1!=0 but 1*0=0;
Thanks, but it produces a wrong answer again
Posted by Petar Zhivkov Petrov 22 Apr 2001 03:02
Re: Thanks, but it produces a wrong answer again
Posted by Nazar Revutsky 22 Apr 2001 03:10
Check if number>9;
22=2*11 where 11>9 and you must print -1
39=3*13 ->   -1
A fool mistake!!!
Posted by Petar Zhivkov Petrov 22 Apr 2001 19:58
I thought that if it's not possible u must print 1, now I
saw that it's -1.
Yeah, this task contains some good traps, is't it ? :)
Posted by Marat Bakirov 23 Apr 2001 19:17
:))))