Carries

frog has nn integers a1,a2,…,ana1,a2,…,an, and she wants to add them pairwise.

Unfortunately, frog is somehow afraid of carries (进位). She defines hardness h(x,y)h(x,y)for adding xx and yy the number of carries involved in the calculation. For example, h(1,9)=1,h(1,99)=2h(1,9)=1,h(1,99)=2.

Find the total hardness adding nn integers pairwise. In another word, find

∑1≤i<j≤nh(ai,aj)∑1≤i<j≤nh(ai,aj)

.

Input

The input consists of multiple tests. For each test:

The first line contains 11 integer nn (2≤n≤1052≤n≤105). The second line contains nnintegers a1,a2,…,ana1,a2,…,an. (0≤ai≤1090≤ai≤109).

Output

For each test, write 11 integer which denotes the total hardness.

Sample Input

2
5 5
10
0 1 2 3 4 5 6 7 8 9

Sample Output

1
20 //题意: n 个数,C(n,2) 这两个数可能进位,问,所有的进位次数是多少? //题解: 容易想到,枚举可能进位的位置,最多也就9次么,然后二分找可能进位的个数
答案要LL,还wa了一发
 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define LL long long
#define lowbit(x) ((x)&(-x))
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MOD 1000000007 inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 100005
/**************************/
int n;
int a[MX];
int yu[MX]; int bi_search(int l,int r,int w)
{
int pos = -;
while (l<=r)
{
int mid = (l+r)/;
if (yu[mid]>=w)
{
pos = mid;
r = mid-;
}
else l = mid+;
}
return pos;
} int main()
{
while (scanf("%d",&n)!=EOF)
{
int mmm=;
for (int i=;i<=n;i++)
{
a[i] =scan();
mmm = max(mmm,a[i]);
}
LL ans = ;
int y = ;
while(y)
{
y*=;
for (int i=;i<=n;i++)
yu[i] = a[i]%y;
sort(yu+,yu++n);
for (int i=;i<=n;i++)
{
int pos = bi_search(,n,y-(a[i]%y));
if (pos!=-)
{
int num = n-pos+;
if (a[i]%y<yu[pos]) ans += (LL)num;
else ans += (LL)num-;
}
}
if (y>mmm) break;
}
printf("%lld\n",ans/);
}
return ;
}
 

最新文章

  1. Boostrap入门(一)
  2. [Python Fabric] [SSH] Mac OS X 10.9 + Vagrant虚拟环境使用Python Fabric进行SSH远程登录的简单实验
  3. windows 修改hosts
  4. SignalR 2.0 系列: 开始使用SignalR 2.0
  5. bzoj1877: [SDOI2009]晨跑
  6. 自适应单本小说网站源码,基于bootstrap+dedecms。
  7. get值乱码(gbk编码浏览器造成)
  8. Eclipse dynamic web project 插件
  9. uva11059(最大乘积)
  10. jvm内存模型-回收算法-和内存分配以及jdk、jre、jvm是什么关系(阿里,美团,京东面试题)
  11. iOS中 MPMoviePlayer 实现视频音频播放 作者:韩俊强
  12. xl2tpd[26104]: Maximum retries exceeded for tunnel 33925. Closing
  13. python基本数据类型 数字 和 字符串
  14. mac book docker
  15. .NET拾忆:EventLog(Windows事件日志监控)
  16. 通过GCEASY 和 jfr 发现运行时问题
  17. 对synchronized的一点理解
  18. JAVA 设计模式之原型模式
  19. 浏览器不支持JavaScript怎么办
  20. Classloader中loadClass()方法和Class.forName()区别

热门文章

  1. Android-RelativeLayout布局技巧(一)
  2. flask-Migrate模块
  3. How to learn a new technology
  4. lucene: nDocs must be &gt; 0查询异常解决
  5. 【MyBatis学习06】输入映射和输出映射
  6. Quartz.net基于数据库的任务调度管理(Only.Jobs)
  7. Cocos2dx报OpenGL error 0x0506错误
  8. redis主从和主从切换
  9. C#实现svn server端的hook
  10. HTML里面的文本标签