j33vansh

Question 2 Divisors Java Solution

Apr 20th, 2022 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Divisor {
  5.  
  6.     static FastReader sc;
  7.     static PrintWriter out;
  8.  
  9.     public static void main(String[] args) {
  10.        
  11.             sc = new FastReader(new InputStreamReader(System.in));
  12.             out = new PrintWriter(System.out);
  13.             solve();
  14.        
  15.         out.flush();
  16.         out.close();
  17.     }
  18.  
  19.     static void solve() {
  20.  
  21.         int t = sc.nextInt();
  22.         while (t-->0) {
  23.             int x = sc.nextInt();
  24.             int ans = 0;
  25.             int ans1 = 0;
  26.             for (int i = 1; i <=x; i++) {
  27.                 if(x%i==0){
  28.                     if(i%2==0){
  29.                         ans +=i;
  30.  
  31.                     }else{
  32.                         ans1 +=i;
  33.                     }
  34.                 }
  35.             }
  36.             out.println(Math.abs(ans-ans1));
  37.         }
  38.     }
  39.  
  40.     /*************/
  41.     static class FastReader {
  42.         BufferedReader br;
  43.         StringTokenizer st;
  44.  
  45.         public FastReader(Reader r) {
  46.             br = new BufferedReader(r);
  47.         }
  48.  
  49.         String next() {
  50.             while (st == null || !st.hasMoreElements()) {
  51.                 try {
  52.                     st = new StringTokenizer(br.readLine());
  53.                 } catch (IOException e) {
  54.                     e.printStackTrace();
  55.                 }
  56.             }
  57.             return st.nextToken();
  58.         }
  59.  
  60.         int nextInt() {
  61.             return Integer.parseInt(next());
  62.         }
  63.  
  64.         long nextLong() {
  65.             return Long.parseLong(next());
  66.         }
  67.  
  68.         double nextDouble() {
  69.             return Double.parseDouble(next());
  70.         }
  71.  
  72.         int[] readArrayI(int n) {
  73.             int[] arr = new int[n];
  74.             for (int i = 0; i < n; i++) {
  75.                 arr[i] = sc.nextInt();
  76.             }
  77.             return arr;
  78.         }
  79.  
  80.         long[] readArrayL(int n) {
  81.             long[] arr = new long[n];
  82.             for (int i = 0; i < n; i++) {
  83.                 arr[i] = sc.nextLong();
  84.             }
  85.             return arr;
  86.         }
  87.  
  88.         String nextLine() {
  89.             String str = "";
  90.             try {
  91.                 str = br.readLine();
  92.             } catch (IOException e) {
  93.                 e.printStackTrace();
  94.             }
  95.             return str;
  96.         }
  97.  
  98.         boolean hasNext() {
  99.             if (st != null && st.hasMoreTokens()) {
  100.                 return true;
  101.             }
  102.             String tmp;
  103.             try {
  104.                 br.mark(1000);
  105.                 tmp = br.readLine();
  106.                 if (tmp == null) {
  107.                     return false;
  108.                 }
  109.                 br.reset();
  110.             } catch (IOException e) {
  111.                 return false;
  112.             }
  113.             return true;
  114.         }
  115.     }
  116.  
  117.     /*
  118.      * ASCII Range--->(A-Z)--->[65,90]<<::>>(a-z)--->[97,122]
  119.      */
  120.     /**************/
  121. }
Add Comment
Please, Sign In to add comment