add: 220210-CN

This commit is contained in:
Lam Haoyin 2022-02-10 20:19:55 +08:00
parent 37372e4c1b
commit 5ea3532fd5
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 20 additions and 1 deletions

19
2202/220210-CN.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <vector>
#include <string>
#include <numeric>
class Solution {
private:
inline static std::string genStr(int x, int y) {
return std::to_string(x) + "/" + std::to_string(y);
}
public:
static std::vector<std::string> simplifiedFractions(int n) {
std::vector<std::string> ret;
for (int i = 2; i < n; ++i)
for (int j = 1; j < i; ++j)
if (1 == std::gcd(i, j))
ret.push_back(genStr(j, i));
return ret;
}
};

View File

@ -3,4 +3,4 @@ PROJECT(2202)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2202 220209-CN.cpp)
ADD_EXECUTABLE(2202 220210-CN.cpp)