题意
Sol
分块打表,非常好的思想。
对于这种求$[A, B]$区间内xxx的数的个数,然后$B$又不算是特别大的题,考虑分段打表
每个块的大小为$10^5$,打$3 * 10^3$个。然后块内的暴力查,块外的暴力算
/* */ #include<cstdio> #include<cstdlib> #include<ctime> const int N = 3e8; int sqr[N], ans = 0, base = 1e5; void check(int x) { for(int i = 2; i * i <= x; i++) if(x % i == 0) return ; int j = 18000; for(int i = 1; sqr[i] < x; i++) { while(sqr[i] + sqr[j] > x) j--; if(sqr[i] + sqr[j] == x) {ans++; return ;} } } main() { freopen("biao.out", "w", stdout); for(int i = 1; i <= 18000; i++) sqr[i] = i * i; for(int i = 1; i <= N; i++) { check(i); if(i % base == 0) printf("%d,", ans); } return 0; } /* */ 打表程序