fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9. public static void main(String[] args) throws IOException {
  10. int n = Integer.parseInt(br.readLine().trim());
  11. String[] arr_a = br.readLine().split(" ");
  12. int[] a = new int[n];
  13. for(int i_a=0; i_a<arr_a.length; i_a++)
  14. {
  15. a[i_a] = Integer.parseInt(arr_a[i_a]);
  16. }
  17.  
  18. long out_ = solve(a);
  19. System.out.println(out_);
  20.  
  21. wr.close();
  22. br.close();
  23. }
  24. static long solve(int[] a){
  25. // Write your code here
  26. int i,j;
  27. long s=0;
  28. double mod = 10000000011.0;
  29. for(i=0;i<a.length;i++){
  30. j = bitset(a[i]);
  31. System.out.println("j " + j);
  32. System.out.println("power " + power(j,i+1,mod));
  33. s =(long) ((s + power((long)(j),i+1,mod)));
  34.  
  35. }
  36. return (long) (s%mod);
  37. }
  38.  
  39. static int bitset(int x){
  40. int count = 0;
  41. while(x!=0){
  42. x = x&(x-1);
  43. count++;
  44. }
  45. return count;
  46. }
  47.  
  48. static long power(long x, int y,double p){
  49.  
  50. long res = 1; // Initialize result
  51.  
  52.  
  53. while (y > 0)
  54. {
  55. // If y is odd, multiply x with result
  56. if (y%2!= 0)
  57. res =(long) (((res%p)*x) % p);
  58.  
  59. // y must be even now
  60. y = y>>1; // y = y/2
  61. x =(long) ((x*x)%p);
  62. }
  63. return (long) (res% p);
  64.  
  65. }
  66. }
Success #stdin #stdout 0.14s 50648KB
stdin
10
3 7 15 31 63 1023 1048575 1073741823 536870911 2147483647
stdout
j     2
power    2
j     3
power    9
j     4
power    64
j     5
power    625
j     6
power    7776
j     10
power    1000000
j     20
power    1280000000
j     30
power    6099999285
j     29
power    7145959919
j     31
power    8286079219
2813046877