【AtCoder Beginner Contest 253】D - FizzBuzz Sum Hard

简介: 笔记

题意


题意很简单:给定 n , a , b,求 [ 1 , n ] 以内除去 a 或 b  的倍数的数,剩余的数之和。


思路


应该是用了容斥原理。


3.png

代码


int f(int x) {
  return (1 + x) * x / 2;
}
void solve() {
  int n, a, b; cin >> n >> a >> b;
  int l = lcm(a, b);
  int res = 0;
  cout << f(n) - a * f(n / a) - b * f(n / b) + l * f(n / l) << endl;
}
相关文章
|
机器学习/深度学习 人工智能 Java
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
102 0
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
115 0
|
人工智能 BI
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
130 0
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
100 0
|
Perl
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
119 0