[Codewars] Is my friend cheating?

Is my friend cheating?

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <vector>
using namespace std;
class RemovedNumbers
{
public:
static vector<vector<long long>> removNb(long long n) {
long long sum = n * (n + 1) / 2;
vector<vector<long long>> res;
for(long long a = 1; a <= n; a++) {
long long b = (sum - a) / (a + 1);
if(a * b + a + b == sum and 1 <= b and b <= n and b != a) res.push_back({a,b});
}
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/30/PS/Codewars/is-my-friend-cheating/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.