Topic: Mathematical.
Questions Successfully Completed: 1
1) Multiplication under Modulo | Easy |
Multiplication under Modulo
Time Complexity : O(1)
Space Complexity: O(1)
Question
Input: a = 92233720368547758 b = 92233720368547758 Output: 484266119 Explanation: Multiplication of a and b under modulo M will be 484266119.
static long multiplicationUnderModulo(long a, long b)
{
// long g= 10^9+7; // doesnt work
long g = 1000000007;
long h = a%g;
long j = b%g;
return (h*j)%g;
}
public static void main(String[] args) {
long a= 92233720368547758L;
long b = 92233720368547758L;
System.out.println(multiplicationUnderModulo(a,b));
}
// OUTPUT
//484266119
Thank you for reading :)