Subnumbers

Given a positive integer N, let us define a subnumber of N as a consecutive number of digits NOT starting with 0. For example if 0, it has 7 subnumbers, namely, 1, 10, 102, 1021, 2, 21 and 1 (again). Here is your task: please calculate the sum of all the subnumbers of N. For 1021, the sum is 1+10+102+1021+2+21+1 = 1158. Since the result may be very large, output the answer modulo 1000000007 (1) please.

Input Specification:

Each input file contains one test case, which gives the integer N (0) in a line.

Output Specification:

Print in a line the sum of all N's subnumbers (modulo 1000000007).

Sample Input:

1234567890123456789
 

Sample Output:

332876913
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ms 1000000007u
 4 vector<long long> v;
 5 int main()
 6 {
 7     ios::sync_with_stdio(false);
 8  //     freopen("data.txt","r",stdin);
 9       string ss;
10       long long s=0,sum=0;
11        cin>>ss;
12        reverse(ss.begin(),ss.end());
13        int k=ss.size();
14        v.resize(k,1);
15        for(int i=1;i<k;i++)
16        v[i]=(v[i-1]*10+1)%ms;
17     for(int i=0;i<k;i++)
18     {
19         sum+=(ss[i]-'0')*v[i];
20         if(ss[i]!='0')
21         s=(s+sum)%ms;
22     }
23     cout<<s;
24     return 0;
25 }

 

posted @ 2020-02-09 00:28  一斜星辰酱  阅读(212)  评论(0编辑  收藏  举报