Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.Optional;
  2.  
  3. /**
  4. * Created by siredvin on 01.09.15.
  5. *
  6. * @author siredvin
  7. */
  8. public class SimpleAnswer {
  9. public static void main(String[] args) {
  10. int max = 999*999;
  11. boolean wasFounded = false;
  12. for (int palindromePart = 999; palindromePart > 99; palindromePart--) {
  13. int palindrome = palindromePart*1000 + (palindromePart % 10)*100 + (palindromePart %100 /10)*10 + palindromePart /100;
  14. if (palindrome>max){
  15. continue;
  16. }
  17. int sqrt = (int) (Math.floor(Math.sqrt(palindrome)) - 1);
  18. for (int divider = 999; divider>sqrt;divider--){
  19. if (palindrome % divider == 0 && (palindrome / divider) / 1000 == 0){
  20. System.out.printf("palindrome %d = %d * %d",palindrome,divider, palindrome/divider);
  21. wasFounded = true;
  22. break;
  23. }
  24. }
  25. if (wasFounded){
  26. break;
  27. }
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement