1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-16 20:56:57 +02:00
CodeWars/5kyu/is_my_friend_cheating/solution.cpp
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

46 lines
994 B
C++

#include <vector>
#include <cmath>
class RemovedNumbers
{
static long long get_lower_bound(long long n);
static long long get_complement(long long ax, long long n);
public:
static std::vector<std::vector<long long>> removNb(long long n);
};
long long RemovedNumbers::get_lower_bound(long long n)
{
return (long long)ceil((2 * n - n * n - n) / (-2 * n - 2.0));
}
long long RemovedNumbers::get_complement(long long ax, long long n)
{
auto result = (0.5 * (n * n + n) - ax) / (ax + 1);
if (floor(result) == result)
{
return (long long)result;
}
else
{
return 0;
}
}
std::vector<std::vector<long long>> RemovedNumbers::removNb(long long n)
{
std::vector<std::vector<long long>> result;
for (long long ax = get_lower_bound(n); ax <= n; ax++)
{
auto complement = get_complement(ax, n);
if (complement != 0)
{
result.push_back({ax, complement});
}
}
return result;
}