版本比较
P12226 「WyOJ Round 1」启 · 破茧初阳 题解
正文
增加 6 行删除 6 行
1234556789101111121314157 行未改动2324252627272829303136 行未改动6869707172727374757677787980808182838485868787888990# [P12226 「WyOJ Round 1」启 · 破茧初阳](https://www.luogu.com.cn/problem/P12226)
### 题目
求从公元后 $1$ 年至公元后 $n$ 年有多少年为快乐年? 求从公元后 $1$ 年至公元后 $n$ 年有多少年为快乐年?
快乐年的定义为:能被 $a$ 整除且不能被 $b$ 整除,或者是能被 $c$ 整除的年份,即将闰年定义中的 $4,100,400$ 依次替换为 $a,b,c$。
### 思路
这里有两种情况: 这里有两种情况:- **能被 $a$ 整除且不能被 $b$ 整除**。- **能被 $c$ 整除的年份**。
根据容斥原理,我们就可以写成 $ A + B - A \cap B $。7 行未改动### Code
```cpp#include<bits/stdc++.h> #include<bits/stdc++.h>#define int __int128//注意由于数据过大,需要用到 __int128 来代替 long longusing namespace std;
int T;36 行未改动signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
read(T); while(T--) { read(n),read(a),read(b),read(c); int a_b=lcm(a,b); int a_c=lcm(a,c); int a_b_c=lcm(a_b,c);
int x=n/a-n/a_b; int y=n/c; int x_y=n/a_c-n/a_b_c; print(x+y-x_y); printf("\n"); }
return 0;}```