日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

codeforce 272B Dima and Sequence

發(fā)布時(shí)間:2023/12/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforce 272B Dima and Sequence 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

B. Dima and Sequence

Dima got into number sequences. Now he's got sequence?a1,?a2,?...,?an, consisting of?n?positive integers. Also, Dima has got a function?f(x), which can be defined with the following recurrence:

  • f(0)?=?0;
  • f(2·x)?=?f(x);
  • f(2·x?+?1)?=?f(x)?+?1.

Dima wonders, how many pairs of indexes?(i,?j)?(1?≤?i?<?j?≤?n)?are there, such that?f(ai)?=?f(aj). Help him, count the number of such pairs.

Input

The first line contains integer?n?(1?≤?n?≤?105). The second line contains?n?positive integers?a1,?a2,?...,?an?(1?≤?ai?≤?109).

The numbers in the lines are separated by single spaces.

Output

In a single line print the answer to the problem.

Please, don't use the?%lld?specifier to read or write 64-bit integers in?C++. It is preferred to use the?cin,?cout?streams or the?%I64dspecifier.

Examples

input

3 1 2 4

output

3

input

3 5 3 1

output

1

Note

In the first sample any pair?(i,?j)?will do, so the answer is?3.

In the second sample only pair?(1,?2)?will do.

打表100條,找到規(guī)律。

偶數(shù)找規(guī)律,計(jì)數(shù)找祖宗。

#include<iostream> #include<queue> #include<algorithm> #include<set> #include<cmath> #include<vector> #include<map> #include<stack> #include<bitset> #include<cstdio> #include<cstring> //---------------------------------Sexy operation--------------------------//#define cini(n) scanf("%d",&n) #define cinl(n) scanf("%lld",&n) #define cinc(n) scanf("%c",&n) #define cins(s) scanf("%s",s) #define coui(n) printf("%d",n) #define couc(n) printf("%c",n) #define coul(n) printf("%lld",n) #define debug(n) printf("%d_________________________________\n",n); #define speed ios_base::sync_with_stdio(0) #define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout) //-------------------------------Actual option------------------------------// #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,n,a) for(int i=n;i>=a;i--) #define Swap(a,b) a^=b^=a^=b #define Max(a,b) (a>b?a:b) #define Min(a,b) a<b?a:b #define mem(n,x) memset(n,x,sizeof(n)) #define mp(a,b) make_pair(a,b) #define pb(n) push_back(n) //--------------------------------constant----------------------------------//#define INF 0x3f3f3f3f #define maxn 10000000 #define esp 1e-9 using namespace std; typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef long long ll; //___________________________Dividing Line__________________________________// long long a[40]= {0}; int main() {int n,x;cini(n);while(n--){int sum=0;cini(x);while(x){if(x&1){sum++;x=(x-1)/2;}else x/=2;}a[sum]++;}long long ans=0;for(int i=0; i<40; i++)ans+=a[i]*(a[i]-1)/2;cout<<ans<<endl;return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的codeforce 272B Dima and Sequence的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。