Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1.  
  2. import java.math.BigInteger;
  3. import java.util.Scanner;
  4.  
  5. public class B394 {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. //Кол-во чисел в числе
  10. int temp = scanner.nextInt();
  11. BigInteger p = BigInteger.valueOf(temp);
  12. //Какой-то множитель
  13. temp = scanner.nextInt();
  14. BigInteger x = BigInteger.valueOf(temp);
  15. BigInteger minNumber = BigInteger.valueOf(1);
  16. while(p.intValue() > 1) {
  17. minNumber = minNumber.multiply(BigInteger.valueOf(10));
  18. p = p.subtract(BigInteger.valueOf(1));
  19. }
  20. boolean tag = false;
  21. for(BigInteger i = minNumber; i.compareTo(minNumber.multiply(BigInteger.valueOf(10)).subtract(BigInteger.valueOf(1))) < 0; i = i.add(BigInteger.valueOf(1))) {
  22. long lastDigit = i.remainder(BigInteger.valueOf(10)).longValue();
  23. if (lastDigit != 0) {
  24. BigInteger numberWithoutLast = i.divide(BigInteger.valueOf(10));
  25. BigInteger checkNumber = minNumber.multiply(BigInteger.valueOf(lastDigit)).add(numberWithoutLast);
  26. if(x.intValue() != 1) {
  27. if(i.multiply(x).equals(checkNumber)) {
  28. System.out.println(i);
  29. tag = true;
  30. break;
  31. }
  32. } else {
  33. if(i.equals(checkNumber)){
  34. System.out.println(i);
  35. tag = true;
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. if (!tag) {
  42. System.out.println("Impossible");
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement