-4

Here's the code:

#include<bits/stdc++.h>
using namespace std;
char s[1000007]; 
int main()
{
    int T, n;
    scanf("%d", &T);
    while(T--)
    {
        long long ans=0; 
        scanf("%d%s",&n,s+1);
        for(int i = 1;i <= n; ++i)
            for(int j = 1; i * j <= n && s[i * j] != 49; ++j)
                ans += i * (s[i * j] == 48), s[i * j] = 50;
        printf("%lld\n",ans);
    }
    return 0;
}

I'm confused about what the s+1 part means because earlier in the code, they declared char s[100007]. Would it just mean take in s and add 1 to it?

Elliott
  • 2,603
  • 2
  • 18
  • 35
  • [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Jesper Juhl Oct 03 '22 at 02:41

1 Answers1

2

s is a pointer. Doing a scanf to s+1 reads the input into the memory pointed to by s starting at the byte after the byte that s points to (that is, s[1]). This is done because the for loops all start at 1 (and that's because we want the answer to give a count, thinking the way humans think).

matt
  • 515,959
  • 87
  • 875
  • 1,141