#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NUM 100
int main(void)
{
int i, random_integer, position;
int result[NUM] = {0};
for (i=0; i<1000000; i++)
{
/* rand() mod NUM^2 */
random_integer
= rand() % (NUM
* NUM
);
/* square root */
position
= sqrt(random_integer
);
result[position]++;
}
for (i=0; i<NUM; i++)
{
printf("arr[%d] = %d\n", i
, result
[i
]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hdGguaD4KCiNkZWZpbmUgTlVNIDEwMAoKaW50IG1haW4odm9pZCkKewogICAgaW50IGksIHJhbmRvbV9pbnRlZ2VyLCBwb3NpdGlvbjsKICAgIGludCByZXN1bHRbTlVNXSA9IHswfTsKCiAgICBmb3IgKGk9MDsgaTwxMDAwMDAwOyBpKyspCiAgICB7CiAgICAgICAgLyogcmFuZCgpIG1vZCBOVU1eMiAqLwogICAgICAgIHJhbmRvbV9pbnRlZ2VyID0gcmFuZCgpICUgKE5VTSAqIE5VTSk7CgogICAgICAgIC8qIHNxdWFyZSByb290ICovCiAgICAgICAgcG9zaXRpb24gPSBzcXJ0KHJhbmRvbV9pbnRlZ2VyKTsKCiAgICAgICAgcmVzdWx0W3Bvc2l0aW9uXSsrOwogICAgfQoKICAgIGZvciAoaT0wOyBpPE5VTTsgaSsrKQogICAgewogICAgICAgIHByaW50ZigiYXJyWyVkXSA9ICVkXG4iLCBpLCByZXN1bHRbaV0pOwogICAgfQogICAgcmV0dXJuIDA7Cn0=