Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
31 lines (23 loc) · 1.01 KB

File metadata and controls

31 lines (23 loc) · 1.01 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.others;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.math.BigInteger;
class FastPowerTest {
private void testLong(long n, long k, long m) {
long result = FastPower.calculate(n, k, m);
Assertions.assertEquals(result, BigInteger.valueOf(n).modPow(BigInteger.valueOf(k), BigInteger.valueOf(m)).longValue());
}
private void testBigInteger(BigInteger n, BigInteger k, BigInteger m) {
BigInteger result = FastPower.calculate(n, k, m);
Assertions.assertEquals(result, n.modPow(k, m));
}
@Test
void test() {
testLong(2, 2, 10);
testLong(100, 1000, 20);
testLong(123456, 123456789, 234);
testBigInteger(BigInteger.TEN, BigInteger.TEN, BigInteger.valueOf(4));
testBigInteger(new BigInteger("123456"), new BigInteger("123456789"), new BigInteger("234"));
testBigInteger(new BigInteger("123456789101112"), new BigInteger("12345678910111213"), new BigInteger("567890"));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.