본문 바로가기
알고리즘/백준

[Python/Java] 백준 10430번 - 나머지

by 소꿍 2020. 6. 8.

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

 

10430번: 나머지

첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000)

www.acmicpc.net

 

Python

 

a, b, c = map(int, input().split())
print((a+b)%c, ((a%c) + (b%c))%c, (a*b)%c, ((a%c) * (b%c))%c, sep='\n')

Java

 

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] s = scan.nextLine().split(" ");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		int c = Integer.parseInt(s[2]);

		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);
		
		scan.close();

	}

}

댓글