modular exponentiation c++
C++
// Iterative C++ program to compute modular power
#include <iostream>
using namespace std;
/* Iterative Function to calculate (x^y)%p in O(log y) */
int power(int x, unsigned int y, int p)
{
int res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0) return 0; // In case x is divisible by p;
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
// Driver code
int main()
{
int x = 2;
int y = 5;
int p = 13;
cout << "Power is " << power(x, y, p);
return 0;
}
// This code is contributed by shubhamsingh10
Also in C++:
- Title
- binary search stl in c++
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- body parser
- Category
- C++
- Title
- How to traverse in a tree iterative C++
- Category
- C++
- Title
- double to string c++
- Category
- C++
- Title
- FInd the element which appears more than n/2 times C++
- Category
- C++
- Title
- how to print a string to console in c++
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- leveling system c++
- Category
- C++
- Title
- dijkstra in c++
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- transpose matrix eigen c++
- Category
- C++
- Title
- vector concat c++
- Category
- C++
- Title
- single line if c++
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- print matrix c++
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- c++ loop through int array
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- unordered_set in c++ and ordered set diff
- Category
- C++
- Title
- clear file before writing c++
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- compare function in sort c++ stl
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- set precision in c++
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- E/flutter (20384): [ERROR:flutter/third_party/txt/src/minikin/FontFamily.cpp(184)] Could not get cmap table size! E/flutter (20384): F/flutter (20384): [FATAL:flutter/third_party/txt/src/minikin/FontCollection.cpp(95)] nTypefaces == 0
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- 2927260.eps 2927262.jpg 2927263.ai License free.txt License premium.txt
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- statement that causes a function to end in c++
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- what is meaning of 64 bit integer in c++
- Category
- C++
- Title
- what does map.count() return in c++
- Category
- C++
- Title
- c++ wait for user input
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- number of islands leetcode code
- Category
- C++
- Title
- sqrt in c++
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- vector last c++
- Category
- C++
- Title
- c++ while true
- Category
- C++
- Title
- find in string c++
- Category
- C++
- Title
- peak in c++
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- cs1955 unity vector3
- Category
- C++
- Title
- c++ random numbers
- Category
- C++
- Title
- is x prime?
- Category
- C++
- Title
- c++ code for polynomial addition
- Category
- C++
- Title
- c++ sort vector of objects by property
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- c++ overloaded equality check operator
- Category
- C++
- Title
- c++ push multiple elements to vector
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- how to find hcf in c++
- Category
- C++
- Title
- c++ remove item from list
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- sort a string alphabetically c++
- Category
- C++
- Title
- Create a program that finds the minimum value in these numbers
- Category
- C++
- Title
- cpp pi from acos
- Category
- C++
- Title
- c++ char print align
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- c++ pi
- Category
- C++
- Title
- c++ loop trhought object
- Category
- C++
- Title
- mkdir boost filesystem
- Category
- C++
- Title
- c++ remove space from string
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- class in c++
- Category
- C++
- Title
- max element in array c++ stl
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- sorting of array in c++
- Category
- C++
- Title
- iterate through unordered_map c++ in reverse order
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- multiset c++
- Category
- C++
- Title
- range based for loop c++ with reference
- Category
- C++
- Title
- screen record ios simulator
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++