HDU 1796 How many integers can you find the repulsion theorem

Source: Internet
Author: User

How many integers can you find

Time limit:12000/5000 MS (java/others) Memory limit:65536/32768 K (java/others)

Problem Description Now I get a number N, and a m-integers set, you should find out how many integers which is small t Han N, that they can divided exactly by any integers in the set. For example, n=12, and M-integer set are {2,3}, so there are another set {2,3,4,6,8,9,10}, all the integers of the set can B e divided exactly by 2 or 3. As a result, you just output the number 7.

Input There is a lot of cases. For each case, the first line contains integers N and M. The follow line contains the M integers, and all of the them is different from each other. 0<n<2^31,0<m<=10, and the M integer is non-negative and won ' t exceed 20.

Output for each case, output the number.

Sample Input12 22 3

Sample Output7

Authorwangye

Source2008 "Insigma International Cup" Zhejiang Collegiate Programming Contest-warm up (4) Idea: The simplest allowance, note may enter 0; odd plus even minus 12. 2 2 3 ANS=11/2+11/3-11/6;
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell __int64#defineMoD 1000000007#defineINF 999999999//#pragma COMMENT (linker, "/stack:102400000,102400000")intScan () {intres =0, ch;  while( ! (ch = getchar ()) >='0'&& CH <='9' ) )    {        if(ch = = EOF)return 1<< - ; } Res= CH-'0' ;  while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;} ll a[ the];ll ji;ll ans,x,y;ll gcd (ll x,ll y) {returny==0? X:GCD (y,x%y);}voidDfs (ll lcm,ll pos,ll step) {if(lcm>x)return; if(pos==ji) {        if(step==0)            return; if(step&1) ans+=x/LCM; Elseans-=x/LCM; return; } DFS (Lcm,pos+1, step); DFS (LCM/GCD (A[POS],LCM) *a[pos],pos+1, step+1);}intMain () {ll z,i,t;  while(~SCANF ("%i64d%i64d",&x,&y)) {x--; Ji=0;  for(i=0; i<y;i++) {scanf ("%i64d",&z); if(z==0)Continue; A[ji++]=Z; } ans=0; DFS (1,0,0); printf ("%i64d\n", ans); }    return 0;}

HDU 1796 How many integers can you find the repulsion theorem

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.