fork download
  1. import java.util.*;
  2.  
  3. class Ideone
  4. {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. int t = sc.nextInt();
  8. while (t-- > 0) {
  9. solve(sc);
  10. }
  11. sc.close();
  12. }
  13.  
  14. public static void solve(Scanner sc)
  15. {
  16. int x=0;int max=x-1;
  17. x=sc.nextInt();
  18. for(int i=1;i<x;i++)
  19. {
  20. if(x%i==0)
  21. {
  22. if(max==x-1)
  23. max=Math.max(max+1,i+i);
  24. else
  25. max=Math.max(max,i+i);
  26. }
  27.  
  28. }
  29. if(max==x-1)
  30. System.out.println(max);
  31. else
  32. {
  33. System.out.println(max/2);
  34. }
  35. }
  36.  
  37. }
  38.  
  39.  
Success #stdin #stdout 0.15s 56692KB
stdin
7
10
7
21
100
2
1000
6
stdout
5
1
7
50
1
500
3