Untitled
raw download clone
C
views 104
,
size 1200 b
#include<stdio.h>
#include<string.h>
#define MOD 1000000007
char temp[2000005];
int x;
char s[1000006];
long long int l,add,s_len;
void substring(int a,int b);

int main ()
{
    int t;
    int flat=1;
    scanf("%d",&t);
    while(t--)
    {

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