문제 링크: https://www.acmicpc.net/problem/10430
백준 입출력과 사칙연산 10단계 - 10430번 나머지를 풀어보았다.
풀이: A, B, C를 입력받아 계산하면 된다.
C++
#include <iostream>
using namespace std;
int main() {
int A, B, C;
cin >> A >> B >> C;
cout << (A+B)%C<<'\n';
cout << ((A%C)+(B%C))%C<<'\n';
cout << (A*B)%C<<'\n';
cout << ((A%C)*(B%C))%C;
}
Python
A,B,C=map(int,input().split())
print((A+B)%C)
print(((A%C)+(B%C))%C)
print((A*B)%C)
print(((A%C)*(B%C))%C)
Java
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int A=sc.nextInt();
int B=sc.nextInt();
int C=sc.nextInt();
System.out.println((A+B)%C);
System.out.println(((A%C)+(B%C))%C);
System.out.println((A*B)%C);
System.out.println(((A%C)*(B%C))%C);
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
고양이 풀이 (0) | 2022.12.30 |
---|---|
곱셈 풀이 (2) | 2022.12.30 |
킹, 퀸, 룩, 비숍, 나이트, 폰 풀이 (0) | 2022.12.30 |
1998년생인 내가 태국에서는 2541년생?! 풀이 (0) | 2022.12.30 |
??! 풀이 (0) | 2022.12.30 |