[BOJ] 1476번 : 날짜 계산

2024. 10. 4. 08:30Algorithm

1. problem : 

https://www.acmicpc.net/problem/1476

 

2. solution 1:

#include <bits/stdc++.h>
using namespace std;
int e, s, m; 
int gcd(int a, int b) {
	if (b == 0) return a; 
	return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> e >> s >> m; 
	e--, s--, m--; 

	int i = e; 
	while (i % 28 != s) i += 15; 

	int l = lcm(15, 28); 
	while (i % 19 != m) i += l; 
	cout << i + 1;
}

source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x12/solutions/6064.cpp

 

basic-algo-lecture/0x12/solutions/6064.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com

0-based로 바꾸는 이유는 알겠지만, 100% 이해가 가지 않는다. 

'Algorithm' 카테고리의 다른 글

[BOJ] 9657번 : 돌 게임 3  (1) 2024.10.06
[BOJ] 1520번 : 내리막 길  (0) 2024.10.05
[BOJ] 2133번: 타일 채우기  (0) 2024.10.03
[BOJ] 9613번 : GCD 합  (0) 2024.10.03
[BOJ] 2294번 : 동전 2  (0) 2024.10.03