This is the title from the Rujia algorithm competition introductory Classic, which is described in the book
Given the positive integers n and M, the number of square-squared factors that are output in [M, N]. PS (without the concept of square factor number, please own Baidu)
#include <stdio.h> #include <string.h> #include <math.h>bool visited[10000005];int prime[500000]; int main () {int n, m;scanf ("%d", &n, &m), int i, j, c = 0;int r = sqrt (n + 0.5), memset (visited, 0, sizeof (visited)); for (i = 2; I <= R; i++) {if (!visited[i]) {prime[c++] = i;for (j = i * i; j <= N; j + = i) visited[j] = 1;}} memset (visited, 0, sizeof (visited)); for (i = 0; i < C; i++) {for (j = prime[i] * Prime[i]; j <= N; j + = Prime[i] * PR Ime[i]) visited[j] = 1;} for (i = m; i <= N; i++) {if (!visited[i]) printf ("%d", I);} return 0;}
The idea given in the book is to sift through the primes first, then use the prime number to filter the square-free factor.
Number of initial---without square factor in several rounds