Description

 

Input

Output

 

Sample Input

3

Sample Output

1
 

Data Constraint

 
做法:,因为𝑎 = 𝑏时肯定无解,我们不妨设𝑎 > 𝑏。 那么有gcd(𝑎, 𝑏) ≤ 𝑎 − 𝑏, 𝑎 𝑥𝑜𝑟 𝑏 ≥ 𝑎 − 𝑏,很明显有𝑐 = 𝑎 − 𝑏。我们依然 枚举𝑐, 𝑎 = 𝑖 ∗ 𝑐,因为gcd(𝑎, 𝑎 − 𝑐) = 𝑐,所以我们只需判断𝑎 𝑥𝑜𝑟 𝑐 = 𝑎 − 𝑐即 可,时间O(𝑛 log 𝑛)。
 
代码如下:
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 using namespace std;
 5 int n;
 6 long long ans;
 7 
 8 int gcd(int x, int y)
 9 {
10     while (y != 0)
11     {
12         int tmp = x;
13         x = y;
14         y = tmp % y;    
15     }    
16     return x;
17 }
18 
19 int main()
20 {
21     scanf("%d", &n);
22     for (int i = 1; i <= n / 2 ; i++)
23     {
24         for (int j = 2; i * j <= n; j++)
25             if (i * (j - 1) == (i ^ (i * j))) ans++;
26     }
27     cout << ans;
28 }
View Code