【题解】Count Dividing XOR

题目传送门

简单数学题

性质

zzy 曾说过:数学,先猜后证。

考虑寻找一个量与 R − L R-L RL 有关。

整体一共涉及三个量: A , B , A ⊕ B A,B,A\oplus B A,B,AB

很自然的想到枚举 A ⊕ B A\oplus B AB

证明

A ⊕ B = C A\oplus B = C AB=C,则 C C C 整除 A A A 也乘除 B B B,故 C C C 也整除 B − A B-A BA,则 C ≤ B − A C \leq B-A CBA

所以枚举 A ⊕ B A\oplus B AB A A A 即可。

Code

#include<bits/stdc++.h>
#define int long long
using namespace std;
int l,r,ans=0;
signed main() {
	cin >> l >> r;
	for(int i = 1; i <= r-l; i++){
		for(int j = (l+i-1) / i*i; i+j <= r; j += i){
			if((i^j)%i == 0 && (i^j) > j && (i^j) <= r){//用到一个性质,B^A^A=B , 注意限定 B 的范围
				ans++;
			}
        }
	}
	cout << ans;
	return 0;
}

I f   I   C o u l d   I ′ d   N e v e r   L e a v e . I   W i l l   S t i l l   B u r n i n g   i n   t h e   H e a t . F o r   L a s t   S u m m e r . I f   I   C o u l d   I ′ d   H i t   R e p e a t .   I   W i l l   B u i l d   a   T i m e   m a c h i n e . T a k e   M e   B a c k   t o   L a s t   S u m m e r . If\ I\ Could\ I'd\ Never\ Leave.\\ I\ Will\ Still\ Burning\ in\ the\ Heat.\\ For\ Last\ Summer.\\ If\ I\ Could\ I'd\ Hit\ Repeat.\ \\ I\ Will\ Build\ a\ Time\ machine.\\ Take\ Me\ Back\ to\ Last\ Summer. If I Could Id Never Leave.I Will Still Burning in the Heat.For Last Summer.If I Could Id Hit Repeat. I Will Build a Time machine.Take Me Back to Last Summer.

  • 11
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bamboo_Day

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值