Samkit5025

Untitled

Jun 10th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. // Solution by Samkit
  2.  
  3. import java.util.*;
  4.  
  5. public class UserMainCode {
  6.  
  7. static Scanner sc = new Scanner(System.in);
  8.  
  9. public static int minimumMoves(int N){
  10. int ans = N;
  11. for(int i=2;i*i<=N;i++) {
  12. if(N%i==0) {
  13. ans = i;
  14. break;
  15. }
  16. }
  17. return 1 + ((N-ans)/2);
  18. }
  19.  
  20. public static void main(String[] args) {
  21. int N = sc.nextInt();
  22.  
  23. System.out.println(minimumMoves(N));
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment