Untitled
raw download clone
C
views 17
,
size 1088 b
#include<stdio.h>
#include<string.h>
#define MOD 1000000007
char subStr[2000005];
int x;
char Str[2000005];
long long int l, add, sLen;
void substring(int a,int b);

int main (void)
{
    int t;
    scanf("%d",&t);
    while(t--)
    {

        scanf("%d",&x);
        scanf("%s",Str);
        sLen = l = strlen(Str);
        for(int i = 1;i <= x;i++)
        {
            int left = Str[i - 1] - '0';
            add = ((l - i) % MOD)*(left - 1);
            l =(l + add) % MOD;
            if(sLen <= x && left > 1)
            {
                substring(i,sLen - 1);
                long long int subLen = strlen(subStr);
                for(int j = 1;j <= left - 1 && sLen <= x;j++)
                {
                    strcat(Str, subStr);
                    sLen += subLen;
                }
            }
        }
        if(l < 0) l += MOD;
        printf("%lld\n", l);
    }
}
void substring(int a,int b)
{
    memset(subStr, '\0', strlen(subStr));
    for(int i = a;i <= b;i++)
    {
        subStr[i - a] = Str[i];
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.