BOJ 10430 나머지


개요

BOJ 10430 나머지

[[분류:BOJ {{{단계}}}단계]]

  • 1단계
  • 나머지 연산을 하고 계산한 결과와 계산을 한 결과를 나머지 연산한 결과가 같은지를 살펴봅니다
  • 알고리즘 분류: 사칙연산, 나머지 연산

C

#include <stdio.h>
int main() {
	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;
}

C++

#include <iostream>
using namespace std;
int main() {
    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 << endl;
    return 0;
}

C#

using System;
public class Program {
    public static void Main() {
        string s = Console.ReadLine();
        string[] ss = s.Split();
        int a = int.Parse(ss[0]);
        int b = int.Parse(ss[1]);
        int c = int.Parse(ss[2]);
        Console.WriteLine( (a+b)%c );
        Console.WriteLine( (a%c + b%c)%c );
        Console.WriteLine( (a*b)%c );
        Console.WriteLine( (a%c * b%c)%c );
    }
}

Go

package main
import "fmt"
func main() {
    var a, b, c int
    fmt.Scanf("%d %d %d", &a, &b,&c)
    fmt.Printf("%d\n", (a+b)%c )
    fmt.Printf("%d\n", (a%c + b%c)%c )
    fmt.Printf("%d\n", (a*b)%c )
    fmt.Printf("%d\n", (a%c * b%c)%c )
}

Java

import java.util.*;
public 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 );
    }
}

node.js

var fs = require('fs');
var input = fs.readFileSync('/dev/stdin').toString().split(' ');
var a = parseInt(input[0]);
var b = parseInt(input[1]);
var c = parseInt(input[2]);
console.log( (a+b)%c );
console.log( (a%c + b%c)%c );
console.log( (a*b)%c );
console.log( (a%c * b%c)%c );

Perl

use 5.010;
($a, $b, $c) = split(/ /, <>);
say( ($a + $b) % $c );
say( ($a % $c + $b % $c) % $c );
say( ($a * $b) % $c );
say( ($a % $c * $b % $c) % $c );

PHP

<?php
fscanf(STDIN,"%d %d %d",$a,$b,$c);
fprintf(STDOUT,"%d\n", ($a+$b)%$c );
fprintf(STDOUT,"%d\n", ($a%$c + $b%$c)%$c );
fprintf(STDOUT,"%d\n", ($a*$b)%$c );
fprintf(STDOUT,"%d\n", ($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 )

R

fp=file("stdin", "r")
a=scan(file=fp, what=integer(0), n=1)
b=scan(file=fp, what=integer(0), n=1)
c=scan(file=fp, what=integer(0), n=1)
cat( (a+b)%%c, "\n")
cat( (a%%c + b%%c)%%c, "\n")
cat( (a*b)%%c, "\n")
cat( (a%%c * b%%c)%%c , "\n")

Ruby

a, b, c = gets.split.map(&:to_i)
puts (a+b)%c
puts (a%c + b%c)%c
puts (a*b)%c
puts (a%c * b%c)%c