12733 - Salary thief
raw download clone
C
views 25
,
size 833 b
#include <stdio.h>
#include <string.h>
#define E ((int)1e9+7)

char s[10000001], r[10000001];

int main(void)
{
    int t, x;
    long long l, temp, ans;

    scanf("%d", &t);
    for(int i=1; i<=t; i++)
    {
        scanf("%d", &x);
        memset(s, '\0', 10000001);
        scanf("%s", s);
        ans = strlen(s);
        l = strlen(s);
        for(int j=1; j<=x; j++)
        {
            temp = (((ans - j) % E) * ((s[j-1] - '0' - 1) % E)) % E;
            ans = (ans + temp) % E;

            if(l <= x)
            {
                strcpy(r, s+j);
                for(int k=1; k<=s[j-1]-'0'-1; k++)
                    strcat(s,r);
                l = strlen(s);
            }
        }
        if(ans < 0)
            ans += E;
        printf("%lld\n", ans);
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.