容斥定理的主干
一、容斥定理的二分制遍历
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
// 关于二进制枚举:两层 for 循环 , 第一层用来枚举集合(一共 1 << x (即 2^x)个集合),
// 第二层用来枚举集合内的元素(母集合一共x 个元素,子集合选择取或不取),
for(int i=1;i<(1<<n);i++)//(1<<n)==2^n//如果i==0 开始循环则有 0 0 0 三个都不选 从i=1开始循环 可以出去这种情况
{
for(int j=0;j<n;j++)
{
cout<<(1&(i>>j))<<" ";
}
cout<<endl;
}
return 0;
}
//这个地方读者可以拿几组数据自己来调一调,理解的更快一点,这个是用来判断 ,主要是用来判断
//从primeNum中选几个质因子相乘得q ,位运算很容易给大家整晕哈,但是用起来很是灵活 ,比如题目上的第二组测
//试数据,primeNum = 1,为2,那么i=1时能够判断i<(1<<primeNum),也就是说只有从1个数中取一个的情况,
//如果primeNum = 2,那么就有从2个中取1个,和2个中取2个的情况,一共有3中情况 (2个中取1个d的是两种)
重点:int 范围 1e9 long long 1e18
Co-prime
Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.
Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than 1 or, equivalently, if their greatest common divisor is 1. The number 1 is relatively prime to every integer.
Input
The first line on input contains T (0 < T <= 100) the number of test cases, each of the next T lines contains three integers A, B, N where (1 <= A <= B <= 10 15) and (1 <=N <= 10 9).
Output
For each test case, print the number of integers between A and B inclusive which are relatively prime to N. Follow the output format below.
Sample Input
2
1 10 2
3 15 5
Sample Output
Case #1: 5
Case #2: 10
Hint
In the first test case, the five integers in range [1,10] which are relatively prime to 2 are {1,3,5,7,9}.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[110];
int main()
{
int t;
cin>>t;
int k=0;
while(t--)
{
k++;
ll A,B,n;
cin>>A>>B>>n