728x90
๋ฌธ์ œ

(A+B)%C๋Š” ((A%C) + (B%C))%C ์™€ ๊ฐ™์„๊นŒ?

(A×B)%C๋Š” ((A%C) × (B%C))%C ์™€ ๊ฐ™์„๊นŒ?

์„ธ ์ˆ˜ A, B, C๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์œ„์˜ ๋„ค ๊ฐ€์ง€ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— A, B, C๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (2 ≤ A, B, C ≤ 10000)

 

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— (A+B)%C,

๋‘˜์งธ ์ค„์— ((A%C) + (B%C))%C,

์…‹์งธ ์ค„์— (A×B)%C,

๋„ท์งธ ์ค„์— ((A%C) × (B%C))%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);
    
    
}

+ Recent posts