-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMainClass.java
63 lines (47 loc) · 1015 Bytes
/
MainClass.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package recursion;
import java.util.Scanner;
public class MainClass {
static int stepCount;
public static void main(String[] args) {
// System.out.println(pow(3 ,10000));
// System.out.println("steps " + stepCount);
//
// stepCount = 0 ;
// System.out.println(fastpow(3 ,10000));
// System.out.println("steps " + stepCount);
Scanner sc = new Scanner (System.in) ;
int a = sc.nextInt();
System.out.println(a);
String s = sc.nextLine();
System.out.println(s);
}
static int sum (int n) {
if(n == 1) {
return 1 ;
}
return n + sum(n-1) ;
}
static int pow(int a , int b) {
stepCount++;
if(b == 0) {
return 1 ;
}
return pow( a , b-1) * a ;
}
static int fastpow(int a , int b) {
stepCount++;
if(b == 0 ) {
return 1 ;
}
if (b % 2 == 0){
return fastpow(a*a , b/2);
}
return a * fastpow(a , b-1 ) ;
}
static int path (int m , int n ) {
if(m==1 || n==1) {
return 1 ;
}
return path(m-1 , n) + path (m , n-1);
}
}