51-nod-1284 2 3 5 7 Multiple

Source: Internet
Author: User
1284. reference time limit of 2 3 5 7: 1 second space limit: 65536 kb score: 5 gives a number N, evaluate 1 to n, the number is not a multiple of 2, 3, 5, and 7. For example, if n = 10, only 1 is not a multiple of 2, 3, 5, and 7. Input
Enter 1 N (1 <= n <= 10 ^ 18 ).
Output
The total number of outputs is not a multiple of 2, 3, 5, and 7.
Input Example 10 output Example 1 because N is very large, direct enumeration is not feasible, but the solution can be quickly obtained by using the exclusion theorem. It is the knowledge of high school mathematics. That is to say, sometimes it is difficult to calculate some things directly, so first calculate all, and then subtract the non-conforming things. To calculate the size of the union of several sets, we need Single SetAnd then subtract all Intersection of Two SetsAnd add all Intersection of three setsAnd then subtract all Intersection of Four SetsAnd so on. Intersection of all sets. The result is N-(n/2 + N/3 + N/5 + N/7-n/6-n/10-n/14-n/15-n/21-n/35 + N/30 + N/ 42 + N/70 + N/105-n/210 )); reference blog: http://www.cppblog.com/vici/archive/2011/09/05/155103.html
#include<cstdio>int main(){    __int64 n;    scanf("%I64d",&n);    printf("%I64d",n-(n/2+n/3+n/5+n/7-n/6-n/10-n/14-n/15-n/21-n/35+n/30+n/42+n/70+n/105-n/210));    return 0;}

 

51-nod-1284 2 3 5 7 Multiple

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.