Thank you for registering 100,000 paiza.
What is this
There was a paiza 100,000 registration thank you special W campaign.
It seems that it is popular to summarize, so both me and me.
By the way, my uncle is only in C language.
algorithm
--Prepare a big array
--Mark the loaded s_i * s_j
--Count from p_i and output the number advanced to the mark
code
I wrote it down and didn't know which one I submitted (ぉ)
Probably this one.
i,j,S[1<<20],F[4096];
main(X)
{
for(;~scanf("%d",F+i++);)
for(j=*S=*F+2;j<i;S[X<S-F?X:0]=1)
X=F[i-1]*F[j++];
for(i=1;++i-*S;printf("%d\n",j-X))
for(X=j=F[i];!S[j];++j);
}
It's basically the same as fuyutsubaki.
A snake foot named commentary
- Read M, N, p \ _m, s \ _n into array F.
- M = F [0], N = F [1], p \ _m = F [2 .. F [0] +2], s \ _n = F [F [0] +2 .. F [1] It will be in +2].
(\ * S is subscripted with F [0] +2 == s_0)
- While reading, calculate X = s_i \ * s_j and set S [X] to 1 if it falls into the big array S.
(To check if it fits, I calculate the size of the big array S with SF, but it seems that it is the reverse (FS), but it can not be helped because the gcc at hand drops that code. .)
- For p_m, count and output the number from the big array S [p_m] until a non-zero value appears.
Self-criticism
- At first, I thought about the code size as "the number of bytes in the executable file" and rewrote printf to putchar, and thought too much.
- I was too particular about 1000000.
- I thought too much about taking advantage of the side effects with the qsort function.
- Treating the array as char and trying to find the number up to the mark with the strlen function, I thought too much.
- If s_i and s_j are elementary, the Chinese Remainder Theorem can be used, right? I thought, and my interest turned to a side street.
- I wasn't a basic golfer, but I couldn't do it too much.
That's all from the field.