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 l≤x≤r . 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 1≤t≤500 ) — 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 1≤l≤r≤1000 ) — 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;
}