You are viewing a single comment's thread. Return to all comments →
// a = {a1, a2, a3} = {1,2,3} // t0 = 0 // s0 = 0 // t1 = t0*10 + 1*a1 = 1 // s1 = s0 + t1 = 1 // t2 = t1*10 + 2*a2 = 2 + 12 // s2 = s1 + t2 = 1 + 2 + 12 // t3 = t2*10 + 3*a3 = 3 + 23 + 123 // s3 = s2 + t3 = (1 + 2 + 12) + (3 + 23 + 123) // ... int substrings(string str) { long long s = 0, t = 0; for(long long i = 1; i <= str.size(); i++) { t = (t * 10 + i * (str[i-1] - '0')) % 1000000007; s = (s + t) % 1000000007; } return s; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sam and substrings
You are viewing a single comment's thread. Return to all comments →