Number of initial---without square factor in several rounds

Source: Internet
Author: User
Tags rounds

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.