Please check my code for finding multiplicative inverse -my answer is coming wrong

import java.util.*;
public class Main {
static Scanner scn = new Scanner(System.in);

public static void main(String[] args) {
	int n = scn.nextInt();
	int p = 1000000007;
	int ans = power(n, p - 2, p);
	System.out.println(ans);
}

public static int power(int a, int n, int m) {
	a = a % m;
	if (n == 1)
		return a;

	int ans = power(a, n / 2, m) % m;
	ans = (ans * ans) % m;
	if (n % 2 == 0)
		return ans;
	else
		return (ans * a) % m;
}

}

@ritik
Use long instead of int everywhere

Please close your doubt is if it resolved