- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find modulus of a number by concatenating n times in Python

Suppose we have a number A. We have to generate a large number X by concatenating A, n times in a row and find the value of X modulo m.

So, if the input is like A = 15 n = 3 m = 8, then the output will be 3, because the number x will be 151515, and 151515 mod 8 = 3.

To solve this, we will follow these steps −

- if A is same as 0, then
- return 0

- an:= A
- c:= number of digits in A
- c:= 10^c
- d:= c-1
- newmod := d*m
- val := (c ^ n mod newmod) -1
- val :=(val + newmod) mod newmod
- an :=(an * val) mod newmod
- return floor of (an / d)

## Example

Let us see the following implementation to get better understanding −

def solve(A, n, m): if A == 0: return 0 an=A c=len(str(A)) c=10**c d=c-1 newmod = d*m val = pow(c,n,newmod)-1 val = (val+newmod) % newmod an = (an*val) % newmod return an // d A = 15 n = 3 m = 8 print(solve(A, n, m))

## Input

15, 3, 8

## Output

3

- Related Articles
- Program to generate array by concatenating subarrays of another array in Python
- Program to find remainder after dividing n number of 1s by m in Python
- Program to rotate a string of size n, n times to left in Python
- Python Program to Find Element Occurring Odd Number of Times in a List
- Program to find replicated list by replicating each element n times
- Compute modulus division by a power-of-2-number in C#
- Program to count number of on lights flipped by n people in Python
- Python Program to calculate n+nm+nmm.......+n(m times).
- Program to find minimum number of days to eat N oranges in Python
- Program to find higher number with same number of set bits as n in Python?
- Calculate n + nn + nnn + … + n(m times) in Python program
- Program to find number of items left after selling n items in python
- Program to print maximum number of characters by copy pasting in n steps in Python?
- Python Program to Search the Number of Times a Particular Number Occurs in a List
- Program to find number of pairs from N natural numbers whose sum values are divisible by k in Python

Advertisements