Problem:


Score : 900 points

Problem Statement

For a positive integer n, let us define f(n) as the number of digits in base 10.

You are given an integer S.
Count the number of the pairs of positive integers (l, r) (l \leq r) such that f(l) + f(l + 1) + ... + f(r) = S, and find the count modulo 10^9 + 7.

Constraints

1 \leq S \leq 10^8

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer.

Sample Input 1

1

Sample Output 1

9

There are nine pairs (l, r) that satisfies the condition: (1, 1), (2, 2), ..., (9, 9).

Sample Input 2

2

Sample Output 2

98

There are 98 pairs (l, r) that satisfies the condition, such as (1, 2) and (33, 33).

Sample Input 3

123

Sample Output 3

460191684

Sample Input 4

36018

Sample Output 4

966522825

Sample Input 5

1000

Sample Output 5

184984484



Sample input:
1


Sample output:
9

Submission status: Wrong Answer

Solution code:
def countDigit(n): 

    count = 0

    while n != 0: 

        n //= 10

        count+= 1

    return count 

  
# Driver Code     

n = 345289467

print ("Number of digits : % d"%(countDigit(n)))

Submission status: Wrong Answer

Solution code:
def val(c): 
    if c >= '0' and c <= '9': 
        return ord(c) - ord('0') 
    else: 
        return ord(c) - ord('A') + 10; 
  
# Function to convert a number  
# from given base 'b' to decimal  
def toDeci(str,base): 
    llen = len(str) 
    power = 1 #Initialize power of base 
    num = 0     #Initialize result 
  
    # Decimal equivalent is str[len-1]*1 +  
    # str[len-1]*base + str[len-1]*(base^2) + ...  
    for i in range(llen - 1, -1, -1): 
          
        # A digit in input number must  
        # be less than number's base  
        if val(str[i]) >= base: 
            print('Invalid Number') 
            return -1
        num += val(str[i]) * power 
        power = power * base 
    return num 
      
# Driver code 
strr = "11A"
base = 16
print('Decimal equivalent of', strr,  
              'in base', base, 'is',  
                 toDeci(strr, base))

Submission status: Wrong Answer

Solution code:
import math 
  
# function to print number of 
# digits 
def findNumberOfDigits(n, base): 
      
    # Calculating log using base 
    # changing property and then 
    # taking it floor and then  
    # adding 1. 
    dig = (math.floor(math.log(n) /
                 math.log(base)) + 1) 
      
    # printing output 
    print ("The Number of digits of"
      " Number {} in base {} is {}"
            . format(n, base, dig)) 
  
# Driver method  
  
# taking inputs 
n = 1446
base = 7
  
# calling the method 
findNumberOfDigits(n, base)

Submission status: Wrong Answer

Solution code:
def  countSetBits(n): 
    count = 0
    while (n): 
        count += n & 1
        n >>= 1
    return count 
  
  

i = 9
print(countSetBits(i))

Submission status: Wrong Answer

Solution code:
# A Simple Python program to compute sum 
# of digits in numbers from 1 to n 

  
# Returns sum of all digits in numbers  
# from 1 to n 

def sumOfDigitsFrom1ToN(n) : 

  

    result = 0   # initialize result 

   

    # One by one compute sum of digits  

    # in every number from 1 to n 

    for x in range(1, n+1) : 

        result = result + sumOfDigits(x) 

   

    return result 

  
# A utility function to compute sum of  
# digits in a given number x 

def sumOfDigits(x) : 

    sum = 0

    while (x != 0) : 

        sum = sum + x % 10

        x   = x // 10

      

    return sum

  

  
# Driver Program 

n = 328

print("Sum of digits in numbers from 1 to", n, "is", sumOfDigitsFrom1ToN(n)) 

  

  
# This code is contributed by Nikita

Submission status: Wrong Answer

Solution code:
def sum(a, n):  

  

    # map to keep a count of occurrences  

    cnt = dict() 

  

    # Traverse in the list from start to end  

    # number of times a[i] can be in a pair and  

    # to get the difference we subtract pre_sum.  

    ans = 0

    pre_sum = 0

    for i in range(n):  

        ans += (i * a[i]) - pre_sum  

        pre_sum += a[i]  

  

        # if the (a[i]-1) is present then  

        # subtract that value as f(a[i], a[i]-1)=0  

        if (a[i] - 1) in cnt: 

            ans -= cnt[a[i] - 1]  

  

        # if the (a[i]+1) is present then add that   

        # value as f(a[i], a[i]-1)=0 here we add  

        # as a[i]-(a[i]-1)<0 which would have been  

        # added as negative sum, so we add to remove   

        # this pair from the sum value  

        if (a[i] + 1) in cnt: 

            ans += cnt[a[i] + 1]  

  

        # keeping a counter for every element  

        if a[i] not in cnt: 

            cnt[a[i]] = 0

        cnt[a[i]] += 1

      

    return ans  

  
# Driver Code  

if __name__ == '__main__': 

    a = [1, 2, 3, 1, 3] 

    n = len(a) 

    print(sum(a, n))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import math

class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_bf(n)
        else:
            return self.is_prime_mr(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_bf(self, n):
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_mr(self, n):
        d = n - 1
        while d % 2 == 0:
            d //= 2

        witnesses = self.get_witnesses(n)

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y ** 2) % n
                d *= 2

            if y != n - 1 and d % 2 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 38255123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes


def gcd(a, b):
    if a < b:
        a, b = b, a
    while 0 < b:
        a, b = b, a % b
    return a


def powmod(a, x, m):
    y = 1
    while 0 < x:
        if x % 2 == 1:
            y *= a
            y %= m
        x //= 2
        a = a ** 2
        a %= M

    return y

M = 10 ** 9 + 7
prime = Prime()


def solve(s):

    if s == 1:
        return 9

    ans = 0

    n = 1
    while True:
        c = 9 * 10 ** (n - 1)
        f = n * c
        if s <= f:
            break
        n += 1

    ans += s // n

    for log_r in range(n - 1, n + 1):
        c_r = 9 * 10 ** (log_r - 1)
        sum_r = log_r * c_r
        for log_l in range(1, log_r):
            mid_f = 0
            for i in range(log_l + 1, log_r):
                mid_f += i * 9 * 10 ** (i - 1)
            if s <= mid_f:
                continue
            res = s - mid_f
            c_l = 9 * 10 ** (log_l - 1)
            if log_l * c_l + sum_r < res:
                continue
            g = gcd(log_r, log_l)
            if res % g != 0:
                continue
            c_l_max = min(c_l, (res - 1) // log_l)
            while 0 < c_l_max:
                if (res - log_l * c_l_max) % log_r == 0: break
                c_l_max -= 1
            if c_l_max == 0:
                continue
            c_l_min = 1
            if sum_r < res:
                c_l_min = (res - sum_r + log_l - 1) // log_l
            div = log_r // g
            ans += (c_l_max - c_l_min + div) // div


    factors = prime.find_factors(s)
    num_prime_factors = len(factors)
    prime_factors = []
    count_limit = []
    count = [0] * num_prime_factors
    for k in factors.keys():
        prime_factors.append(k)
        count_limit.append(factors[k])

    loop = True
    while loop:
        p = 1
        for i, f in enumerate(prime_factors):
            p *= f ** count[i]
        if n <= p:
            ans += 9 * powmod(10, p - 1, M)
            ans += M - s // p
            ans %= M

        count[0] += 1
        for i, limit in enumerate(count_limit):
            if limit < count[i]:
                if i == num_prime_factors - 1:
                    loop = False
                    break
                count[i + 1] += 1
                count[i] = 0

    return ans

def main():
    s = int(input())

    print(solve(s))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import math

class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_bf(n)
        else:
            return self.is_prime_mr(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_bf(self, n):
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_mr(self, n):
        d = n - 1
        while d % 2 == 0:
            d //= 2

        witnesses = self.get_witnesses(n)

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y ** 2) % n
                d *= 2

            if y != n - 1 and d % 2 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 38255123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes


def gcd(a, b):
    if a < b:
        a, b = b, a
    while 0 < b:
        a, b = b, a % b
    return a


def powmod(a, x, m):
    y = 1
    while 0 < x:
        if x % 2 == 1:
            y *= a
            y %= m
        x //= 2
        a = a ** 2
        a %= M

    return y

M = 10 ** 9 + 7
prime = Prime()


def solve(s):

    if s == 1:
        return 9

    ans = 0

    n = 1
    while True:
        c = 9 * 10 ** (n - 1)
        f = n * c
        if s <= f:
            break
        n += 1

    ans += s // n

    for log_l in range(1, n):
        for log_r in range(max(log_l + 1, n - 1), n + 1):
            mid_f = 0
            for i in range(log_l + 1, log_r):
                mid_f += i * 9 * 10 ** (i - 1)
            if s <= mid_f:
                continue
            res = s - mid_f
            c_l = 9 * 10 ** (log_l - 1)
            c_r = 9 * 10 ** (log_r - 1)
            if log_l * c_l + log_r * c_r < res:
                continue
            g = gcd(log_r, log_l)
            if res % g != 0:
                continue
            c_l_max = min(c_l, (res - 1) // log_l)
            while 0 < c_l_max:
                if (res - log_l * c_l_max) % log_r == 0: break
                c_l_max -= 1
            if c_l_max == 0:
                continue
            c_l_min = 1
            if log_r * c_r < res:
                c_l_min = (res - log_r * c_r + log_l - 1) // log_l
            div = log_r // g
            ans += (c_l_max - c_l_min + div) // div


    factors = prime.find_factors(s)
    num_prime_factors = len(factors)
    prime_factors = []
    count_limit = []
    count = [0] * num_prime_factors
    for k in factors.keys():
        prime_factors.append(k)
        count_limit.append(factors[k])

    loop = True
    while loop:
        p = 1
        for i, f in enumerate(prime_factors):
            p *= f ** count[i]
        if n <= p:
            q = s // p
            ans += 9 * powmod(10, p - 1, M)
            ans += M - q
            ans %= M

        count[0] += 1
        for i, limit in enumerate(count_limit):
            if limit < count[i]:
                if i == num_prime_factors - 1:
                    loop = False
                    break
                count[i + 1] += 1
                count[i] = 0

    return ans

def main():
    s = int(input())

    print(solve(s))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())
dv = []
mod = 10**9+7
for i in range(1,int((s+0.5)**0.5)+1):
  if s%i == 0:
    if s//i != i:
      dv.append(s//i)
    dv.append(i)
dv.sort()
ans = 0
cnt = 0
for i in dv:
  if s//i <= 8:
    break
  ans += pow(10,(s//i)-1,mod)*9-i
  ans %= mod
  cnt += 1
ans += (s-1)//8
t = s
for i in range(1,11):
  minus = i*9*10**(i-1)
  if minus > t:
    mx = (t+i-1)//i+10**(i-1)
    break
  else:
    t -= minus
bettable = [[[0,0] for i in range(9)] for j in range(9)]
for i in range(9):
  for j in range(i+1,9):
    for k in range(i+1,j):
      bettable[i][j][0] += k*10**(k-1)*9
      bettable[i][j][1] += 10**(k-1)*9
for i in range((s+7)//8,mx):
  avgl = s//i
  if avgl*i == s and 10**(avgl-1)*9 >= i:
    ans += 10**(avgl-1)*9-i+1
    continue
  avgh = avgl+1
  for l in range(1,avgl+1):
    for h in range(avgh,9):
      t = s-bettable[l][h][0]
      j = i-bettable[l][h][1]
      if t < 0 or j < 0:
        continue
      lnum = min(j,10**(l-1)*9)
      hnum = min(j,10**(h-1)*9)
      if (h*j-t)%(h-l) == 0:
        x = (h*j-t)//(h-l)
        if 0 < x <= lnum and 0 < j-x <= hnum:
          ans += 1
          break
print(ans%mod)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

from fractions import gcd
import numpy as np

MOD = 10 ** 9 + 7

S = int(input())

M = 10**4

def type_1(S):
    cnt = 0
    # S 2種の桁数k,k+1からなる。さらにk>=9を仮定する。
    # 項数nとすると、kn < S < (k+1)n となる(k,n)の個数を数える
    # まずk > Mとなるものを数える。このとき1<=n<=Mである。
    n = np.arange(1,M+1)
    k_max = (S-1)//n
    k_min = np.maximum(M+1,S//n)
    cnt += np.maximum(0,k_max - k_min + 1).sum()
    # 次に、9<=k<=Mとなるものを数える
    k = np.arange(9,M+1)
    n_max = (S-1)//k
    n_min = S//(k+1) + 1
    cnt += np.maximum(0,n_max-n_min+1).sum()
    return cnt

type_1(S)

def type_2(S):
    # S 1種の桁数からなる。
    cnt = 0
    div = np.arange(1,M+1,dtype=np.int64)
    div = set(div[S%div==0])
    div |= set(S//x for x in div)
    for d in div:
        n = S//d
        # d桁のものをn個使うようにしたい
        if d < 10:
            total = 9 * 10 ** (d-1)
            cnt += max(0,total-n+1)
        else:
            total = 9 * pow(10,int(d)-1,MOD)
            cnt += total-n+1
    return cnt % MOD

def type_3(S):
    cnt = 0
    # S 2種以上の桁数からなる。9桁の数以下しか使わない。
    # ここは適当にいけそう
    for R in range(1,10):
        for L in range(1,R):
            mid = sum(i*9*10**(i-1) for i in range(L+1,R)) # 途中の桁数の寄与
            rest = S - (L+mid+R)
            if rest < 0:
                continue
            # Lが1+x個、Rが1+y個として
            # Lx + Ry = rest, 0<=x<=x_max, 0<=y<=y_max
            x_max = 9*10**(L-1)-1
            y_max = 9*10**(R-1)-1
            g = gcd(L,R)
            if rest % g != 0:
                continue
            L0 = L//g
            R0 = R//g
            rest //= g
            # x mod R0が一意に決まる
            for x0 in range(R0):
                if (L0*x0-rest)%R0 == 0:
                    break
            y0 = (rest-L0*x0)//R0
            # (x0 + tR, y0-tL)として解がパラメータ表示できる
            # 0 <= x0 + tR <= x_max
            t_min = 0
            t_max = (x_max-x0)//R0
            # y0-tL >= 0
            t_max = min(t_max,y0//L0)
            # y0-tL <= y_max iff y0-y_max <= tL
            t_min = max(t_min,(y0-y_max+L-1)//L0)
            cnt += max(0, t_max - t_min + 1)
    return cnt

answer = (type_1(S) + type_2(S) + type_3(S)) % MOD
print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math
import random

class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_bf(n)
        else:
            return self.is_prime_mr(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_bf(self, n):
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_mr(self, n):
        d = n - 1
        while d % 2 == 0:
            d //= 2

        witnesses = self.get_witnesses(n)
        #witnesses = [random.randint(1, n - 1) for _ in range(100)]

        for w in witnesses:
            t = d
            y = pow(w, t, n)

            while t != n - 1 and y != 1 and y != n - 1:
                y = (y ** 2) % n
                t *= 2

            if y != n - 1 and t % 2 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 38255123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes


def gcd(a, b):
    if a < b:
        a, b = b, a
    while 0 < b:
        a, b = b, a % b
    return a


def powmod(a, x, m):
    y = 1
    while 0 < x:
        if x % 2 == 1:
            y *= a
            y %= m
        x //= 2
        a = a ** 2
        a %= M

    return y

M = 10 ** 9 + 7
prime = Prime()


def solve(s):

    if s == 1:
        return 9

    ans = 0

    n = 1
    c = 9
    while n * c < s:
        n += 1
        c *= 10

    ans += s // n

    for log_r in range(n - 1, n + 1):
        c_r = 9 * 10 ** (log_r - 1)
        sum_r = log_r * c_r
        for log_l in range(1, log_r):
            mid_f = 0
            for i in range(log_l + 1, log_r):
                mid_f += i * 9 * 10 ** (i - 1)
            if s <= mid_f:
                continue
            res = s - mid_f
            c_l = 9 * 10 ** (log_l - 1)
            if log_l * c_l + sum_r < res:
                continue
            g = gcd(log_r, log_l)
            if res % g != 0:
                continue
            c_l_max = min(c_l, (res - 1) // log_l)
            while 0 < c_l_max:
                if (res - log_l * c_l_max) % log_r == 0: break
                c_l_max -= 1
            if c_l_max == 0:
                continue
            c_l_min = 1
            if sum_r < res:
                c_l_min = (res - sum_r + log_l - 1) // log_l
            div = log_r // g
            ans += (c_l_max - c_l_min + div) // div


    factors = prime.find_factors(s)
    num_prime_factors = len(factors)
    prime_factors = []
    count_limit = []
    count = [0] * num_prime_factors
    for k in factors.keys():
        prime_factors.append(k)
        count_limit.append(factors[k])

    loop = True
    while loop:
        p = 1
        for i, f in enumerate(prime_factors):
            p *= f ** count[i]
        if n <= p:
            ans += 9 * powmod(10, p - 1, M)
            ans += M - s // p
            ans %= M

        count[0] += 1
        for i, limit in enumerate(count_limit):
            if limit < count[i]:
                if i == num_prime_factors - 1:
                    loop = False
                    break
                count[i + 1] += 1
                count[i] = 0

    return ans

def main():

    s = int(input())

    print(solve(s))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
range = xrange
S = int(raw_input())
MOD = 10**9+7
ans = 0

# l has <= 7 digits
r = 1
tot = 1
for l in range(1, 10000000):
    while tot < S:
        r+= 1
        tot+= len(str(r))
    if tot == S: ans+= 1
    tot-= len(str(l))

# l has > 7 digits
for cnt in range(1, S+1):
    d, m = divmod(S, cnt)
    if d <= 7: break
    if m: ans+= 1
    else: ans+= pow(10, d, MOD) - pow(10, d-1, MOD) - cnt + 1
    ans%= MOD
print ans % MOD

Submission status: Runtime Error

Solution code:
define(n)
for int i in range(0,9)
print(" ")

if (l>9)
print("n+l digits");
else:

for(r>l)
print("r-l+n digits");

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
inf = 10**10
G = [{} for i in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    G[l-1][r-1] = d
    G[r-1][l-1] = -d
V = [False for i in range(n)]
D = [inf for i in range(n)]
for i in range(n):
    if V[i]:
        continue
    #helloo
    Q = [i]
    D[i] = 0
    while Q:
        j = Q.pop()
        V[j] = True
        for k in G[j].keys():
            if not V[k]:
                Q.append(k)
            if D[k] == inf:
                D[k] = D[j]+G[j][k]
            elif D[k] != D[j]+G[j][k]:
                print('No')
                exit()
print('Yes')

Submission status: Runtime Error

Solution code:
#include<iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=50000005;
int s,len[N],p[N];
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    p[0]=1;
    scanf("%d",&s);
    ll ans=0;
    int sum=0;
    for(int l=1,r=0;l<10000000;l++)
    {
        while(sum<s)
        {
            r++;
            p[r]=p[r-1];
            len[r]=len[r-1];
            if(r/p[r]!=0) p[r]*=10,len[r]++;
            sum+=len[r];
        }
        if(sum==s) ans++;
        sum-=len[l];
    }
    for(int t=1;t<=s/8;t++)
    {
        if(s%t) ans=(ans+1)%mod;
        else ans=(ans+(qpow(10,s/t)-qpow(10,s/t-1)-t+1))%mod;
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}

Submission status: Runtime Error

Solution code:
#Sumit

def sumOfDigitsFrom1ToN(n) 
    result = 0
    for x in range(1, n+1) : 

        result = result + sumOfDigits(x)

    return result 


def sumOfDigits(x) : 

    sum = 0

    while (x != 0) : 

        sum = sum + x % 10

        x   = x // 10

    return sum

 
n = 328

print("Sum of digits in numbers from 1 to", n, "is", sumOfDigitsFrom1ToN(n))

Submission status: Runtime Error

Solution code:
kases = int(raw_input())
for kase in range(kases):
    N = int(raw_input())
    result = 1
    for i in range(1, N + 1):
        result = result * i
    print result

Submission status: Runtime Error

Solution code:
t = eval(input())
data = []
ans = []
for i in range(t):
    data = list(input().split())
    result = (int(data[0]))**(int(data[1]))
    transtr = len(str(result))
    ans.append(transtr)
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
# include <bits/stdc++.h>
#include<cstdio>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
const int maxn = 23000000;
short dig[maxn+1];
inline void add(int &x, int y)
{
    x+=y;
    if(x>=mod) x-=mod;
}
int qmod(LL a, int b)
{
    LL res = 1;
    for(;b;b>>=1)
    {
        if(b&1) res=res*a%mod;
        a=a*a%mod;
    }
    return (int)res;
}
int main()
{
    for(int i=1; i<=maxn; ++i) dig[i] = dig[i/10]+1;
    int n, ans=0;
    scanf("%d",&n);
    for(int i=1, j=1, s=0; i<1e7; ++i)
    {
        while(s<n) s+=dig[j],++j;
        if(s==n) add(ans, 1);
        s -= dig[i];
    }
    for(int i=1; i<=n/8; ++i)
    {
        if(n%i==0) add(ans, ((qmod(10,n/i)-qmod(10,n/i-1)-i+1)%mod+mod)%mod);
        else add(ans, 1);
    }
    printf("%d\n",ans);
    return 0;
int t=0;
}

Submission status: Runtime Error

Solution code:
# include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long LL;
const int maxn = 23000000;
short dig[maxn+1];
inline void add(int &x, int y)
{
    x+=y;
    if(x>=mod) x-=mod;
}
int qmod(LL a, int b)
{
    LL res = 1;
    for(;b;b>>=1)
    {
        if(b&1) res=res*a%mod;
        a=a*a%mod;
    }
    return (int)res;
}
int main()
{
    for(int i=1; i<=maxn; ++i) dig[i] = dig[i/10]+1;
    int n, ans=0;
    scanf("%d",&n);
    for(int i=1, j=1, s=0; i<1e7; ++i)
    {
        while(s<n) s+=dig[j],++j;
        if(s==n) add(ans, 1);
        s -= dig[i];
    }
    for(int i=1; i<=n/8; ++i)
    {
        if(n%i==0) add(ans, ((qmod(10,n/i)-qmod(10,n/i-1)-i+1)%mod+mod)%mod);
        else add(ans, 1);
    }
    printf("%d\n",ans);
    return 0;
int t=0;
}