F - Double Sum 2 Editorial /

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

正整数 xx に対して f(x)f(x) を「 xx が偶数である間 xx22 で割り続けたときの、最終的な xx の値」として定義します。例えば f(4)=f(2)=f(1)=1f(4)=f(2)=f(1)=1f(12)=f(6)=f(3)=3f(12)=f(6)=f(3)=3 です。

長さ NN の整数列 A=(A1,A2,,AN)A=(A_1,A_2,\ldots, A_N) が与えられるので、 i=1Nj=iNf(Ai+Aj)\displaystyle \sum_{i=1}^N \sum_{j=i}^N f(A_i+A_j) を求めてください。

制約

  • 1N2×1051\le N\le 2\times 10^5
  • 1Ai1071\le A_i\le 10^7
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN
A1A_1 A2A_2 \ldots ANA_N

出力

答えを出力せよ。


入力例 1Copy

Copy
2
4 8

出力例 1Copy

Copy
5

f(A1+A1)=f(8)=1f(A_1+A_1)=f(8)=1f(A1+A2)=f(12)=3f(A_1+A_2)=f(12)=3f(A2+A2)=f(16)=1f(A_2+A_2)=f(16)=1 です。したがって、 1+3+1=51+3+1=5 を出力してください。


入力例 2Copy

Copy
3
51 44 63

出力例 2Copy

Copy
384

入力例 3Copy

Copy
8
577752 258461 183221 889769 278633 577212 392309 326001

出力例 3Copy

Copy
20241214

Score : 500500 points

Problem Statement

For a positive integer xx, define f(x)f(x) as follows: "While xx is even, keep dividing it by 22. The final value of xx after these divisions is f(x)f(x)." For example, f(4)=f(2)=f(1)=1f(4)=f(2)=f(1)=1, and f(12)=f(6)=f(3)=3f(12)=f(6)=f(3)=3.

Given an integer sequence A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) of length NN, find i=1Nj=iNf(Ai+Aj)\displaystyle \sum_{i=1}^N \sum_{j=i}^N f(A_i+A_j).

Constraints

  • 1N2×1051\le N\le 2\times 10^5
  • 1Ai1071\le A_i\le 10^7
  • All input values are integers.

Input

The input is given in the following format from Standard Input:

NN
A1A_1 A2A_2 \ldots ANA_N

Output

Print the answer.


Sample Input 1Copy

Copy
2
4 8

Sample Output 1Copy

Copy
5

f(A1+A1)=f(8)=1f(A_1+A_1)=f(8)=1, f(A1+A2)=f(12)=3f(A_1+A_2)=f(12)=3, f(A2+A2)=f(16)=1f(A_2+A_2)=f(16)=1. Thus, Print 1+3+1=51+3+1=5.


Sample Input 2Copy

Copy
3
51 44 63

Sample Output 2Copy

Copy
384

Sample Input 3Copy

Copy
8
577752 258461 183221 889769 278633 577212 392309 326001

Sample Output 3Copy

Copy
20241214


2025-04-23 (Wed)
12:55:06 +00:00