NYOJ225 小明求素数积
水题。
附ac代码:
#include <stdio.h> #include <math.h> int a[1001]; void Count(){ int i, j, t = (int)sqrt(1001); for(i = 2; i <= t; ++i){ if(a[i]) continue; for(j = i * i; j <= 1000; j += i) a[j] = 1; } } int main(){ int t, n, i, s; Count(); scanf("%d", &t); while(t-- && scanf("%d", &n)){ for(i = 2, s = 1; i <= n; ++i) if(!a[i]){ s *= i; if(s >= 1000000) s %= 1000000; } printf("%d\n", s); } return 0; }