Dora‘s Set

Dora’s Set

题目描述

Dora has a set s s s containing integers. In the beginning, she will put all integers in [ l , r ] [l, r] [l,r] into the set s s s . That is, an integer x x x is initially contained in the set if and only if l ≤ x ≤ r l \leq x \leq r lxr . Then she allows you to perform the following operations:

  • Select three distinct integers a a a , b b b , and c c c from the set s s s , such that gcd ⁡ ( a , b ) = gcd ⁡ ( b , c ) = gcd ⁡ ( a , c ) = 1 † \gcd(a, b) = \gcd(b, c) = \gcd(a, c) = 1^\dagger gcd(a,b)=gcd(b,c)=gcd(a,c)=1 .
  • Then, remove these three integers from the set s s s .

What is the maximum number of operations you can perform?

† ^\dagger Recall that gcd ⁡ ( x , y ) \gcd(x, y) gcd(x,y) means the greatest common divisor of integers x x x and y y y .

输入格式

Each test consists of multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 500 1 \leq t \leq 500 1t500 ) — the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers l l l and r r r ( 1 ≤ l ≤ r ≤ 1000 1 \leq l \leq r \leq 1000 1lr1000 ) — the range of integers in the initial set.

输出格式

For each test case, output a single integer — the maximum number of operations you can perform.

样例 #1

样例输入 #1

8
1 3
3 7
10 21
2 8
51 60
2 15
10 26
1 1000

样例输出 #1

1
1
3
1
2
3
4
250

提示说明

In the first test case, you can choose a = 1 a = 1 a=1 , b = 2 b = 2 b=2 , c = 3 c = 3 c=3 in the only operation, since gcd ⁡ ( 1 , 2 ) = gcd ⁡ ( 2 , 3 ) = gcd ⁡ ( 1 , 3 ) = 1 \gcd(1, 2) = \gcd(2, 3) = \gcd(1, 3) = 1 gcd(1,2)=gcd(2,3)=gcd(1,3)=1 , and then there are no more integers in the set, so no more operations can be performed.

In the second test case, you can choose a = 3 a = 3 a=3 , b = 5 b = 5 b=5 , c = 7 c = 7 c=7 in the only operation.

In the third test case, you can choose a = 11 a = 11 a=11 , b = 19 b = 19 b=19 , c = 20 c = 20 c=20 in the first operation, a = 13 a = 13 a=13 , b = 14 b = 14 b=14 , c = 15 c = 15 c=15 in the second operation, and a = 10 a = 10 a=10 , b = 17 b = 17 b=17 , c = 21 c = 21 c=21 in the third operation. After the three operations, the set s s s contains the following integers: 12 12 12 , 16 16 16 , 18 18 18 . It can be proven that it’s impossible to perform more than 3 3 3 operations.

代码内容

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//队列
// #include <queue>//堆/优先队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve()
{
    ll l,r;
    cin>>l>>r;

    cout<<((r+1)/2-l/2)/2<<endl;
}

int main()
{
    ll t;
    cin>>t;

    while(t--) solve();

    return 0;
}
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Pretty Boy Fox

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

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

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

打赏作者

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

抵扣说明:

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

余额充值