프로그래밍/HackerRank
[HackerRank][Python3] Sam and substrings
snoopybox
2018. 6. 6. 02:25
Problem :
https://www.hackerrank.com/challenges/sam-and-substrings/problem
My Solution :
#!/usr/bin/env python3 def substrings(n): m = 10**9 + 7 dp = [int(n[0])] for i in range(1, len(n)): s = ((i+1)*int(n[i]) + 10*dp[i-1]) % m dp.append(s) ret = 0 for s in dp: ret = (ret + s) % m return ret n = input().strip() result = substrings(n) print(result)