[Programmers] 멀쩡한사각형

Time Lapse :NONE

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using namespace std;

int gcd(int a, int b){
while(b!=0){
int r = a%b;
a= b;
b= r;
}
return a;
}

long long solution(int w,int h)
{
long long answer;
int g = gcd(h,w);
return (long long)h * (long long)w - g*((w/g) + (h/g) -1);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/fineSquare/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.