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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

發布時間:2023/12/10 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Imp is in a magic forest, where xorangles grow (wut?)

A xorangle of order?n?is such a non-degenerate triangle, that lengths of its sides are integers not exceeding?n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order?n?to get out of the forest.

Formally, for a given integer?n?you have to find the number of such triples?(a,?b,?c), that:

  • 1?≤?a?≤?b?≤?c?≤?n;
  • , where??denotes the?bitwise xor?of integers?x?and?y.
  • (a,?b,?c)?form a non-degenerate (with strictly positive area) triangle.

Input

The only line contains a single integer?n?(1?≤?n?≤?2500).

Output

Print the number of xorangles of order?n.

Examples

Input

6

Output

1

Input

10

Output

2

Note

The only xorangle in the first sample is?(3,?5,?6).

題目大意:

問你有多少個非嚴格遞增的三個數a,b,c,滿足a^b^c=0.

解題報告:

? ? 這題因為異或的性質,a^a=0,0^c=c。所以在三元組中,枚舉前兩小的值,那么第三個值其實就已知了。也就是這三個值一定是a? ,? b? ,? a^b。然后把題目那些條件帶進去做判斷就可以了

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; int n; int main() {cin>>n;ll ans = 0;for(int i = 1; i<=n; i++) {for(int j = i; j<=n; j++) {if((i^j)<=n &&(i^j)>=j&&(i+j) > (i^j)) {//printf("%d %d\n",i,j);ans++;}}}printf("%lld\n",ans);return 0 ;}

?

總結

以上是生活随笔為你收集整理的【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。