https://atcoder.jp/contests/typical90/tasks/typical90_v
022 - Cubic Cake(★2)
AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.
atcoder.jp
A* B* C 크기의 빵이있다. 이를 최소한으로 잘라서 모두 같은 크기로 만들어라. 자른 횟수를 구하라.
많이 볼법한 문제이다. A, B, C의 공통된 크기로 만들려면 gcd를 이용한다. 그리고 나눈횟수를 단순히 세주면 된다.
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <numeric>
#include <random>
#include <iostream>
#include <unordered_map>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define range(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
const int INF = 2000000000;
const double pi = 3.14159265358979;
const int MOD = 100000;
void yesno(bool a)
{
if (a)
cout << "YES\n";
else
cout << "NO\n";
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll a, b, c;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> c;
ll g = gcd(a, b);
g = gcd(g, c);
cout << (a / g + b / g + c / g - 3);
return 0;
}
'알고리즘 > atcoder90제' 카테고리의 다른 글
앳코더90 - 026 - Independent Set on a Tree(★4) (0) | 2024.11.20 |
---|---|
앳코더90 - 024 - Select +/- One(★2) (0) | 2024.11.19 |
앳코더90 - 021 - Come Back in One Piece(★5) (0) | 2024.11.15 |
앳코더90 - 020 - Log Inequality(★3) (0) | 2024.11.12 |
앳코더90 - 018 - Statue of Chokudai(★3) (0) | 2024.11.11 |