JZOJ5197 C

Description

Input

Output

Sample Input

3

Sample Output

1

Data Constraint

Hint

Solution

    因为𝑎 = 𝑏时肯定无解,我们不妨设𝑎 > 𝑏。 那么有gcd(𝑎, 𝑏) ≤ 𝑎 − 𝑏, 𝑎 𝑥𝑜𝑟 𝑏 ≥ 𝑎 − 𝑏,很明显有𝑐 = 𝑎 − 𝑏。

    我们依然 枚举𝑐, 𝑎 = 𝑖 ∗ 𝑐,因为gcd(𝑎, 𝑎 − 𝑐) = 𝑐,所以我们只需判断𝑎 𝑥𝑜𝑟 𝑐 = 𝑎 − 𝑐即 可。

 1 #include<cstdio>
 2 using namespace std;
 3 int ans,n;
 4 int main()
 5 {
 6     scanf("%d",&n);
 7     for (int i=1;i<=n;i++)
 8     {
 9         int a=i*2;
10         while (a<=n)
11         {
12             if ((a^i)==a-i)
13                 ans++;
14             a=a+i;
15         }
16     }
17     printf("%d",ans);
18 }
View Code

 

posted @ 2018-08-25 08:44  kasiruto  阅读(267)  评论(0编辑  收藏  举报