{"id":20757,"date":"2021-09-30T11:00:23","date_gmt":"2021-09-30T05:30:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=20757"},"modified":"2021-11-22T18:35:32","modified_gmt":"2021-11-22T13:05:32","slug":"python-program-for-exponential-squaring-fast-modulo-multiplication","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-exponential-squaring-fast-modulo-multiplication\/","title":{"rendered":"Python Program for Exponential Squaring (Fast Modulo Multiplication)"},"content":{"rendered":"

Beginners and experienced programmers can rely on these Best Java Programs Examples<\/a> and code various basic and complex logics in the Java programming language with ease.<\/p>\n

Given two numbers base value and the exponential value, the task is to find the power of base and exponent modular 10^9+7<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given base value =\u00a0 5\r\nGiven exponent value = 3<\/pre>\n

Output:<\/strong><\/p>\n

The value of the power of base and exponent modular 10^9+7 =  125<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given base value =\u00a0 3\r\nGiven exponent value = 10000<\/pre>\n

Output:<\/strong><\/p>\n

The value of the power of base and exponent modular 10^9+7 =  895629451<\/pre>\n

Program for Exponential Squaring (Fast Modulo Multiplication) in Python<\/h2>\n

Below are the ways to find the power of base and exponent modular 10^9+7 for the given base and exponential values:<\/p>\n

Method #1: Using While Loop (Static Input)<\/h3>\n

Approach:<\/strong><\/p>\n