Challenge: Eugene and Big Number
Subdomeniu: Number Theory (number-theory)
Scor cont: 100.0 / 100
Submission status: Accepted
Submission score: 1.0
Submission ID: 464775242
Limbaj: python3
Link challenge: https://www.hackerrank.com/challenges/eugene-and-big-number/problem
Cerinta
Eugene must do his homework, but he is struggling.
He has three integer numbers: *A*, *N*, *M*. He writes number *A* on the board *N* times **in a row**. Let's call the resulting big number *X*.
Help Eugene find *X* [modulo](https://en.wikipedia.org/wiki/Modulo_operation) *M*.
Input Format
First line contains *T*, the number of testcases.
Each testcase contains three numbers: *A*, *N*, *M* separated by a single space.
Output Format
Print the required answer for each testcase in a new line.
Constraints
+ $1 \le T \le 200$
+ $0 \le A \le 10^3$
+ $0 < N < 10^{12}$
+ $1 < M < 10^9$
Cod sursa
#!/bin/python3
import math
import os
import random
import re
import sys
def solve(a, n, m):
digits = len(str(a))
divisor = 10**digits-1
m *= divisor
return (a % m)*(pow(10, digits*n, m)-1) % m // divisor
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
first_multiple_input = input().rstrip().split()
a = int(first_multiple_input[0])
n = int(first_multiple_input[1])
m = int(first_multiple_input[2])
result = solve(a, n, m)
fptr.write(str(result) + '\n')
fptr.close()
HackerRank Number Theory – Eugene and Big Number
