Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class B394 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //Кол-во чисел в числе
- int temp = scanner.nextInt();
- BigInteger p = BigInteger.valueOf(temp);
- //Какой-то множитель
- temp = scanner.nextInt();
- BigInteger x = BigInteger.valueOf(temp);
- BigInteger minNumber = BigInteger.valueOf(1);
- while(p.intValue() > 1) {
- minNumber = minNumber.multiply(BigInteger.valueOf(10));
- p = p.subtract(BigInteger.valueOf(1));
- }
- boolean tag = false;
- for(BigInteger i = minNumber; i.compareTo(minNumber.multiply(BigInteger.valueOf(10)).subtract(BigInteger.valueOf(1))) < 0; i = i.add(BigInteger.valueOf(1))) {
- long lastDigit = i.remainder(BigInteger.valueOf(10)).longValue();
- if (lastDigit != 0) {
- BigInteger numberWithoutLast = i.divide(BigInteger.valueOf(10));
- BigInteger checkNumber = minNumber.multiply(BigInteger.valueOf(lastDigit)).add(numberWithoutLast);
- if(x.intValue() != 1) {
- if(i.multiply(x).equals(checkNumber)) {
- System.out.println(i);
- tag = true;
- break;
- }
- } else {
- if(i.equals(checkNumber)){
- System.out.println(i);
- tag = true;
- break;
- }
- }
- }
- }
- if (!tag) {
- System.out.println("Impossible");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement