【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;
}
相关文章
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
115 0
|
机器学习/深度学习 人工智能 Java
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
108 0
|
人工智能 BI
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
133 0
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
104 0
|
人工智能
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
116 0
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
106 0
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle