The way to learn the principle of tolerance and repulsion theory

Source: Internet
Author: User

December 2014 8-14th, my goal is to fully understand the principle of repulsion, by the way to organize the template!

The principle of tolerance should be very easy in mathematics, it is no longer described here!

Take one of the following topics: Give 2 digital m,n, and find out how many numbers and N coprime are in 1-m (ensure that all numbers do not exceed int type)!

Array implementations

#include <cstdio>int p[10],k;//p array is used to hold the mass factor of n, the int type n will not exceed 10 void getp (int n) {    k=0;    for (int i=2;i*i<=n;i++) {        if (n%i==0) p[k++]=i;        while (n%i==0) n/=i;    }    if (n>1) p[k++]=n;//prevents a mass factor with a greater than n-Root, K preserves the number of factors}int nop (int m) {    int i,j,que[10000],top=0,t,sum;    que[top++]=-1;//Queue array Save n the product for (i=0;i<k;i++) {t=top;//t of any combination of the mass factors for the        current que length, which facilitates the following loops to use the for        (j=0 ; j<t;j++) {            que[top++]=que[j]*p[i]* ( -1);        } The number of quality factors: odd plus even minus, so multiply the number of    i=1,sum=0;i<top;i++} for (//sum) to accumulate all the numbers        sum+=m/que[i];    return sum;} int main () {    int n,m;    while (scanf ("%d%d", &m,&n) ==2) {  //to 1-m How many numbers are associated with n coprime        getp (n);//n Quality Factor        printf ("%d\n", M-nop (m) );//Total minus    }    return 0;}

The way to learn the principle of tolerance and repulsion theory

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.