나머지 (10430)
Created:
그냥 입력값 받고 주어진 대로 연산만 하면 되는 문제.
Bash
Bash 1
2
3
4
5
read a b c
echo $(((a + b) % c))
echo $((((a % c) + (b % c)) % c))
echo $(((a * b) % c))
echo $((((a % c) * (b % c)) % c))
C
C 1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("%d\n", (a+b)%c);
printf("%d\n", ((a%c)+(b%c))%c);
printf("%d\n", (a*b)%c);
printf("%d\n", ((a%c)*(b%c))%c);
return 0;
}
Node.js
JavaScript 1
2
3
4
5
let [a, b, c] = require("fs").readFileSync(0).toString().trim().split(" ").map(Number);
console.log((a+b)%c);
console.log(((a%c)+(b%c))%c);
console.log((a*b)%c);
console.log(((a%c)*(b%c))%c);
PHP
PHP 1
2
3
4
5
6
7
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $c);
echo ($a+$b)%$c."\n";
echo (($a%$c) + ($b%$c))%$c."\n";
echo ($a*$b)%$c."\n";
echo (($a%$c) * ($b%$c))%$c."\n";
?>
Python3
Python 1
2
3
4
5
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 )
Ruby
Ruby 1
2
3
4
5
a, b, c = gets.chomp.split().map {|i| i.to_i}
puts (a+b)%c
puts ((a%c) + (b%c))
puts (a*b)%c
puts ((a%c) * (b%c))