Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17389

time limit exceed in the code that sums the numbers

$
0
0

in the question there will be a number taken from user. Up to that number, I want to find the sum of all numbers if the sum of that number's digits is odd.For example if the input is 13 then ;1+3+5+7+9+10+12 = 47 should be the result.In order to prevent time limit exceed, question says "Since the answer might be too big, please print the answer in modulo 10^9+7"

Constraints1 ≤ n < 10^17 (n is input)

Here is my code:

MOD = 1000000007def getSum(number):    total = 0    while number > 0:        total += number % 10        number //= 10    return (total % MOD) % 2def sticker(number):    stickerNeed = 0    for oneDigit in range(1, number):        if (getSum(oneDigit % MOD) == 1):            stickerNeed += oneDigit    return stickerNeed % MODnumber = int(input())result = sticker(number)print(result % MOD)

But it still cannot handle the really big numbers and gives time limit exceed. Can you help me out? What wrong with my code?


Viewing all articles
Browse latest Browse all 17389

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>