Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- /**
- * @author Daniil Shreyder
- * Date: 16.06.2021
- */
- public class Test {
- public static void main(String[] args) {
- BigInteger inputBase10 = BigInteger.valueOf(2)
- .multiply(BigInteger.valueOf(7).pow(2))
- .add(BigInteger.valueOf(42)
- .multiply(BigInteger.valueOf(49).pow(49)))
- .add(BigInteger.valueOf(-357));
- System.out.println(inputBase10);
- final BigInteger base = BigInteger.valueOf(7);
- BigInteger inputBase7 = convertToBase(inputBase10, base);
- System.out.println(inputBase7);
- System.out.println("Number of 6: " +
- inputBase7.toString()
- .chars()
- .filter(character -> character == '6')
- .count());
- }
- public static BigInteger convertToBase(BigInteger inputBase10, BigInteger base) {
- int counter = 0;
- BigInteger inputBaseX = BigInteger.ZERO;
- while (!inputBase10.equals(BigInteger.ZERO)) {
- inputBaseX = inputBaseX.add(inputBase10.mod(base).multiply(BigInteger.valueOf(10).pow(counter)));
- inputBase10 = inputBase10.divide(base);
- counter++;
- }
- return inputBaseX;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment