문제 출처: www.acmicpc.net/problem/10430
10430번: 나머지
첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000)
www.acmicpc.net
1. 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(void) | |
{ | |
int A, B, C; | |
cin >> A >> B >> C; | |
cout << (A + B) % C << endl; | |
cout << ((A % C) + (B % C)) % C << endl; | |
cout << (A * B) % C << endl; | |
cout << ((A % C) * (B % C)) % C; | |
return 0; | |
} |
2. 풀이
cout으로 출력을 하는데 출력 내용은 문제에 있는 그대로 쓰는데 1가지만 바꾸면 된다. ×를 *로 바꾸기만 하면 된다. 그 이유는 곱하기를 할 때 사용하는 것은 x가 아닌 *이기 때문이다.
'컴퓨터 > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 1330번: 두 수 비교하기 [C++] (0) | 2020.11.23 |
---|---|
백준 알고리즘 2588번: 곱셈 [C++] (0) | 2020.11.22 |
백준 알고리즘 10869번: 사칙연산 [C++] (0) | 2020.11.20 |
백준 알고리즘 1008번: A/B [C++] (0) | 2020.11.19 |
백준 알고리즘 1914번: 하노이 탑 [C++] (0) | 2020.11.18 |