We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main.java.com.poogle.BOJ.Q1629; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long a = sc.nextInt(); long b = sc.nextInt(); long c = sc.nextInt(); System.out.println(calculate(a, b, c) % c); } private static long calculate(long a, long b, long c) { if (b == 0) return 1; else if (b == 1) return a; long tmp = calculate(a, b / 2, c) % c; if (b % 2 == 0) return (tmp * tmp) % c; //짝수일 때 else return (((tmp * tmp) % c) * a) % c; //홀수일 때 } }
The text was updated successfully, but these errors were encountered:
a1468e8
suhyunsim
No branches or pull requests
문제
핵심 아이디어
1-1. 지수(n)가 짝수일 때: a ^ n == (a ^ (n/2)) ^ 2
1-2. 지수(n)가 홀수일 때: a ^ n == ((a ^ (n/2)) ^ 2) * a
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: