Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- String s;
- Scanner in = new Scanner(System.in);
- s = in.nextLine();
- BigInteger k = new BigInteger(s);
- BigInteger[] powsOfNine = new BigInteger[s.length()+1];
- powsOfNine[0] = BigInteger.ONE;
- for(int i = 1; i <= s.length(); i++) {
- powsOfNine[i] = powsOfNine[i-1].multiply(BigInteger.valueOf(9));
- //System.out.println(powsOfNine[i]);
- }
- int j = s.length()-1;
- BigInteger sol = BigInteger.ZERO;
- while(k.compareTo(BigInteger.ZERO) > 0) {
- int digit = 0;
- while(k.subtract(powsOfNine[j]).compareTo(BigInteger.ZERO) >= 0) {
- digit++;
- k = k.subtract(powsOfNine[j]);
- }
- j--;
- System.out.print(digit);
- }
- System.out.println("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement