mhdew

Timus 1014

Mar 29th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define in() freopen("input.txt", "r", stdin)
  5. #define out() freopen("output.txt", "w", stdout)
  6.  
  7. int main()
  8. {
  9.    
  10.     long long n;
  11.  
  12.     scanf("%lld", &n);
  13.     long long sub=n;
  14.     int j=0, flag=0;
  15.     int a[100000];
  16.     long long sum=1;
  17.  
  18.     if(n==1){
  19.         printf("1\n");
  20.     }
  21.     else if(n==0){
  22.         printf("10\n");
  23.     }
  24.     else{
  25.         for(int i=9;i>1;i--){
  26.             if(n%i==0){
  27.                 flag=1;
  28.                 a[j++]=i;
  29.                 n=n/i;
  30.                 i++;
  31.             }
  32.             if(n==1){
  33.                 break;
  34.             }
  35.         }
  36.         if(flag==0){
  37.             printf("-1\n");
  38.         }
  39.         else{
  40.             for(int i=j-1;i>=0;i--){
  41.                 sum=sum*a[i];
  42.             }
  43.             if(sum==sub){
  44.                 for(int i=j-1;i>=0;i--){
  45.                     printf("%d", a[i]);
  46.                 }
  47.                 printf("\n");
  48.             }
  49.             else{
  50.                 printf("-1\n");
  51.             }
  52.         }
  53.     }
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment