Answer to Question #280520 in Python for Rahul Sigh

Question #280520

Odd even prime multiples


Humans have finally made contact with aliens from outer space who call themselves Primes. Naturally, each of their individuals loves prime numbers. Their emperor loves the prime number p the most. However, their maths is much more advanced than the version we use on Earth. They have very long numbers with several digits going up to 100 digits. A number is said to be valid for them if it follows the following conditions:


Task

The emperor has sent the message that he will consider humans an intelligent life form if you can tell him the number of valid numbers between L and R (both inclusive). Since the number of such numbers can be too large, you only need to tell the answer modulo (109+7).


For Full Instructions and Note Please Use Those Images as reference... Please help

https://drive.google.com/file/d/1As_XKXCbB2L2zHCMvbDIZfUiN46_QArO/view?usp=sharing

https://drive.google.com/file/d/1XqxcnlhhjqTTLc8PYcfz7tMdW7AFmcKa/view?usp=sharing
1
Expert's answer
2021-12-20T10:03:56-0500
def mod(num, a):
    # // Initialize result
    res = 0
    for i in range(0,len(num)):
        res = (res * 10 + (int)num[i] - '0') % a;
    
    return res;
}




p = int(input())
l = input()
r = input()
c = 0
for k in range(int(l,int(r)+1):
    i = k
    if mod(i,p) == 0:
        i = str(i)
        for j in (0,len(i)):
            if (j%2 == 0 and i[j] % 2 != 0) or (j%2 != 0 and i[j] % 2 == 0):
                c += 1;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS