Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.  
  2. import java.math.BigInteger;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         String s;
  9.         Scanner in = new Scanner(System.in);
  10.         s = in.nextLine();
  11.         BigInteger k = new BigInteger(s);
  12.         BigInteger[] powsOfNine = new BigInteger[s.length()+1];
  13.         powsOfNine[0] = BigInteger.ONE;
  14.         for(int i = 1; i <= s.length(); i++) {
  15.             powsOfNine[i] = powsOfNine[i-1].multiply(BigInteger.valueOf(9));
  16.             //System.out.println(powsOfNine[i]);
  17.         }
  18.        
  19.         int j = s.length()-1;
  20.         BigInteger sol = BigInteger.ZERO;
  21.         while(k.compareTo(BigInteger.ZERO) > 0) {
  22.             int digit = 0;
  23.             while(k.subtract(powsOfNine[j]).compareTo(BigInteger.ZERO) >= 0) {
  24.                 digit++;
  25.                 k = k.subtract(powsOfNine[j]);
  26.             }
  27.             j--;
  28.             System.out.print(digit);
  29.         }
  30.         System.out.println("");
  31.        
  32.     }
  33.    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement