import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int term; if (N % 2 != 0) { term = (int) Math.pow(2, N / 2); } else { term = (int) Math.pow(3, (N / 2) - 1); } System.out.println(term); } }
n = int(input())
if n == 1 or n == 2:
print(1)
elif n % 2 != 0:
m = n // 2
print(pow(2,m))
else:
n = n - 1
m = n // 2
print(pow(3,m))
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int term;
if (N % 2 != 0) {
term = (int) Math.pow(2, N / 2);
} else {
term = (int) Math.pow(3, (N / 2) - 1);
}
System.out.println(term);
}
}
Can you explain in java sir
Use sliding window 2pointers
Resource : @engineering animuthyam
Exam kab hai