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

WA #3
Posted by Kirill_Khapov 9 Nov 2013 21:57
Here is my program. Throws an error number 3. Tested for n = 10 ^ 9 and n = 0. I can not understand.


#include <iostream>
#include <conio.h>
using namespace std;
main()
{
 long long int a=0,b=0,c=0,n=0,m[10001],d=0;
 cin >> n;
 if (n==0) goto qwerty;
 for (a=9;a>=1;a--)

   while (n % a == 0)
   {
     if ((a==1) && (b>1)) break;
     n/=a;
     b++;
     m[b]=a;
   }
 if (n==1)
 {
 for (a=1;a<=b;a++) for (c=1;c<b;c++)
   if (m[c]>m[c+1]) { m[c]+=m[c+1]; m[c+1]=m[c]-m[c+1]; m[c]-=m[c+1];}
 d=1;
 n=0;
 for (a=b;a>=1;a--) { m[a]*=d; d*=10; n+=m[a]; }
 cout << n;
 }
 else cout << -1;
 qwerty:
 if (n==0) cout << -1;
 getch();
}

Edited by author 09.11.2013 21:58
Re: WA #3
Posted by PanVovan 29 Jun 2014 02:55
n=1
Re: WA #3
Posted by Ameya Sinha 2 Nov 2017 19:40
Have a look at the case n=1