Given an array of N integers A1, A2, A3…AN. If you randomly choose two indexes i ,j such that 1 ≤ i < j ≤ N, what is the expected value of Ai | Aj?

Input

First line contains an integer T, the number of test cases. Each test case consists of two lines. First line denotes the size of array, N and second line contains N integers forming the array.
1 ≤ T ≤ 10 
2 ≤ N ≤ 100,000 
0 ≤ Ai < 231

Output

For each test case, print the answer as an irreducible fraction. Follow the format of the sample output. 
The fraction p/q (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1 that divides both p and q separately.

Example

Input:
2
2
0 0
3
1 2 3 Output:
0/1
3/1

题意:给定一个数列a[],求任意两个数a[i]和a[j]的或运算的期望(i!=j)。

思路:此类题已经是套路了,就是每一位分别看,统计为一位为1和为0的个数。然后根据XOR,或者OR的性质采取相应的措施。

OR的话,就是第i位的贡献是:(C(n,2)-C(num[i],2))/C(n,2)*(1<<i) 。num[i]是第i位为0的个数。

(注意,用unsigned long long)

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll unsigned long long
using namespace std;
ll F,P,G,num[],N,a,b,c,i,j;
int main()
{
int T,x; scanf("%d",&T);
while(T--){
scanf("%lld",&N);
F=; P=(N-)*N/;
c=N*(N-)/;
for(i=;i<;i++) num[i]=;
for(i=;i<=N;i++){
scanf("%d",&x);
for(j=;j<;j++) if(x&(<<j)) num[j]++;
}
for(i=;i<;i++){
F+=(P-(N-num[i])*(N-num[i]-)/)*(1LL<<i);
}
G=__gcd(F,P);
F/=G; P/=G;
printf("%lld/%lld\n",F,P);
}
return ;
}

最新文章

  1. Hadoop_初识
  2. java 19 -14 File类的判断并输出案例
  3. SpringMVC Map Model ModelMap 和 ModelAndView
  4. 高效通信模型之 - 网络通信I/O模式( Windows)
  5. BZOJ 1878 HH的项链
  6. memcache、memcached、groupcache的区别
  7. Light OJ 1033 - Generating Palindromes(区间DP)
  8. mysql 索引相关
  9. 【ANT】创建删除目录,复制移动重命名文件
  10. [Luogu2991][USACO10OPEN]水滑梯Water Slides
  11. ROS机器人程序设计(原书第2版)补充资料 (柒) 第七章 3D建模与仿真 urdf Gazebo V-Rep Webots Morse
  12. week_one-python格式化输出
  13. http接口测试(python)
  14. [20171225]查看并行执行计划注意的问题.txt
  15. 源码分析HotSpot GC过程(一)
  16. MongoDB学习笔记-2(使用java连接Mongo)
  17. swift网络数据请求方法
  18. 0071 CentOS_Tomcat访问文件名包含中文的文件出现404错误
  19. LeetCode 笔记系列十 Suduko
  20. jsonarray 循环

热门文章

  1. javaWeb_Request对象
  2. Spring中Bean的后置处理器
  3. CocoaPods为project的全部target添加依赖支持
  4. 数据库系统学习(七)-SQL语言之复杂查询与视图
  5. 把握linux内核设计思想(十二):内存管理之slab分配器
  6. node 爬虫 --- 批量下载图片
  7. 批量修改文件权限 和所有者 chown nobody:nobody * -R chmod 775 * -R
  8. HashMap变成线程安全方法
  9. flask-本地线程-请求上下文补充
  10. HDU 1022 Train Problem I (数据结构 —— 栈)