-
[C++] Programmers | 멀쩡한 사각형Problem Solving/Programmers 2023. 2. 5. 01:01
멀쩡한 사각형
✅ Accept Code
// programmers week2-6 // 멀쩡한 사각형 #include <bits/stdc++.h> using namespace std; long long GCD(int a, int b) { if (b == 0) return a; else return GCD(b, a % b); } long long solution(int w, int h) { // total - gcd * (w / gcd + h / gcd - 1); return (long long) w * h - (w + h - GCD(w, h)); } /* * long long total = w * h; * return total - (w + h - GCD(w, h)); -> test 12 ~ 17 실패 */
728x90'Problem Solving > Programmers' 카테고리의 다른 글
[C++] Programmers study week #3 (0) 2023.02.05 [C++] Programmers | 괄호 회전하기 (2) 2023.02.05 [C++] Programmers | 숫자 게임 (0) 2023.02.05 [C++] Programmers | 체육복 (0) 2023.02.05 [C++] Programmers | 땅따먹기 (0) 2023.02.05