Skip to content

Commit

Permalink
BOJ-EX: 5/19/2024, 7:57:10 PM
Browse files Browse the repository at this point in the history
  • Loading branch information
fkdl0048 committed May 19, 2024
1 parent 87a5f43 commit f515484
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 1629번: 곱셈/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 1629번: 곱셈 - <img src="https://static.solved.ac/tier_small/10.svg" style="height:20px" /> Silver I

<!-- performance -->

<!-- 문제 제출 후 깃허브에 푸시를 했을 때 제출한 코드의 성능이 입력될 공간입니다.-->

<!-- end -->

## 문제

[문제 링크](https://boj.kr/1629)


<p>자연수 A를 B번 곱한 수를 알고 싶다. 단 구하려는 수가 매우 커질 수 있으므로 이를 C로 나눈 나머지를 구하는 프로그램을 작성하시오.</p>



## 입력


<p>첫째 줄에 A, B, C가 빈 칸을 사이에 두고 순서대로 주어진다. A, B, C는 모두 2,147,483,647 이하의 자연수이다.</p>



## 출력


<p>첫째 줄에 A를 B번 곱한 수를 C로 나눈 나머지를 출력한다.</p>



## 소스코드

[소스코드 보기](곱셈.cpp)
37 changes: 37 additions & 0 deletions 1629번: 곱셈/곱셈.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: ::: ::: */
/* Problem Number: 1629 :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fkdl4878 <boj.kr/u/fkdl4878> +#+ +#+ +#+ */
/* +#+ +#+ +#+ */
/* https://boj.kr/1629 #+# #+# #+# */
/* Solved: 2024/05/19 17:29:57 by fkdl4878 ### ### ##.kr */
/* */
/* ************************************************************************** */

#include <bits/stdc++.h>
using namespace std;

long long mod_exp(long long a, long long b, long long c){
if (b == 0) return 1;
if (b == 1) return a % c;

long long half = mod_exp(a, b / 2, c);
long long result = (half * half) % c;

if (b % 2 != 0){
result = (result * a) % c;
}

return result;
}

int main(){
long long a, b, c;

cin >> a >> b >> c;
cout << mod_exp(a, b, c) << '\n';

return 0;
}
Binary file added 1629번: 곱셈/곱셈.exe
Binary file not shown.

0 comments on commit f515484

Please sign in to comment.