inhuman_Arif

LA 6929

Aug 25th, 2023
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) throws IOException {
  6. //        System.setIn(new FileInputStream(new File("/home/arif/Documents/inout/input.txt")));
  7. //        System.setOut(new PrintStream(new File("/home/arif/Documents/inout/output.txt")));
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         long[] arr = new long[30005];
  11.         arr[1] = 1;
  12.         for (int i=2;i<30002;i++)
  13.             arr[i] = arr[i-1] + i;
  14. //        System.out.println(arr[30001]);
  15.  
  16.         int tc = scanner.nextInt();
  17.         while (tc-- >0) {
  18.             long n = scanner.nextLong();
  19.             long temp = n;
  20.             while(temp%2==0)
  21.                 temp/=2;
  22.             if(temp==1)
  23.                 System.out.println("IMPOSSIBLE");
  24.             else {
  25.                 if (n%2==1)
  26.                     System.out.println(n + " = " + n/2 + " + " + n/2 + 1);
  27.                 else {
  28.                     int ind;
  29.                     for (ind=2;ind<30002;ind++)
  30.                         if ((n-arr[ind])%ind==0)
  31.                             break;
  32.                     long con = (n-arr[ind])/ind;
  33.                     System.out.print(n + " = ");
  34.                     int i;
  35.                     for (i=1;i<ind;i++)
  36.                         System.out.print(i+con + " + ");
  37.                     System.out.println(i+con);
  38.                 }
  39.             }
  40.         }
  41.  
  42.         scanner.close();
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment