https://programmers.co.kr/learn/courses/30/lessons/62048
[풀이 1]
#include<iostream>
using namespace std;
long long gcd(long long a, long long b){
while(b!=0){
long long r = a%b;
a= b;
b= r;
}
return a;
}
long long solution(int w,int h) {
long long answer = (long)w*h;
int g = gcd(w, h);
w = w/g;
h = h/g;
if(w == h)
answer = answer - w * g;
else
answer = answer - (w + h-1) * g;
return answer;
}
#include <iostream>
using namespace std;
int GCD(int a, int b){
if(a == 0) return b;
return GCD(b % a, a);
}
long long solution(int w,int h)
{
long long answer = 1;
int gcd = GCD(w, h);
cout << w + h - gcd;
answer = ((long)w * h) - ((long)w + h - gcd);
return answer;
}
using namespace std;
long long solution(int w, int h) {
long long answer = 0;
for (int i = 0; i < w; ++i) {
answer += (int)((double)h*i/w);
}
return 2 * answer;
}