This commit is contained in:
19
lectures/lec1/Magic.java
Normal file
19
lectures/lec1/Magic.java
Normal file
@@ -0,0 +1,19 @@
|
||||
public class Magic {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(magic());
|
||||
}
|
||||
|
||||
int magic(int a, int n) {
|
||||
int r = 1;
|
||||
while (n != 0) {
|
||||
if (n % 2 == 1) {
|
||||
r *= a;
|
||||
}
|
||||
n /= 2;
|
||||
a *= a;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user