1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); long a = sc.nextLong(); long b = sc.nextLong(); long p = sc.nextLong(); System.out.println(multiply(a, b, p)); } public static long multiply(long a, long b, long p){ long ans = 0 % p; while(b > 0){ if((b&1) == 1){ ans = (ans + a) % p; } a = a * 2 % p; b = b >> 1; } return ans; } }
|