hdu4279-Euler function + approximately several numbers + table +sqrt () accuracy problem

Source: Internet
Author: User
Tags explode

Http://acm.hust.edu.cn/vjudge/problem/31861/origin

The topic asks for a number n, removes its approximate number from "1,n", and removes all its coprime numbers, the number of remaining numbers, if the number is odd, is a real

Find the number of real numbers between the interval "x, y"

First of all the rules of the table found, in fact, also good proof:

First for a number, and its coprime number must be an even number (according to the Euler formula can be obtained), and secondly for the approximate, only the square number of the approximate is odd, the rest are even,

If the number is not a square number

num = N-euler (n)-divisor (n) +1, that is, even non-squared numbers are real number, plus 1 is because 1 even if coprime is also a factor

If it is squared, then only odd squares are real number


If you ask for "1,x" How many real number, first ask how many even, and then subtract even square number Achieva medical number of square number

The even number is N/2, odd squares and even squares, if sqrt (n)%2, the odd number is one, otherwise

Note that sqrt (1.0*n) will explode, sqrt ((double) n) will explode, only sqrt ((Long long Doubel) n) will not

or int x=sqrt (n), if (x*x>n) x--;


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
# Include <algorithm>
#include <queue>
#include <map>
#include <set>
# Include <vector>
#include <iostream>
using namespace std;

Const double Pi=acos ( -1.0);
Double eps=0.000001;

int num[]= {0,0,0,0,0,0,1,1,2,3}; 
Long Long cal1 (long long N)
{
    if (n<=4)
        return 0;
    Long Long ans= (n-4)/2;

    Long Long tmp=sqrt (n);
    if (tmp*tmp>n)
        tmp--;
    if (tmp%2)
        ans++;


    return ans;
}
int main ()
{
    int t;
    cin>>t;
    while (t--)
    {
     long long x, y;
         scanf ("%lld%lld", &x,&y);
         Long Long ret1=cal (x-1);
         Long long ret2=cal (y); 
         printf ("%lld\n", Ret2-ret1); 
    }
    return 0;

}



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.