HDU 1796 How many integers can you find (Getting Started

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions

Gives the set of constant N, the number of M.

Ask:

[0, N-1] How many numbers are multiples of a number in a collection.

Ideas:

Is how many numbers are divisible by at least one number in the set = can be divisible by a number in the set-divisible by 2 and divisible by 3 ...



#include <stdio.h> #include <iostream> #include <algorithm> #include <sstream> #include < stdlib.h> #include <string.h> #include <limits.h> #include <vector> #include <string># Include <time.h> #include <math.h> #include <queue> #include <stack> #include <set># Include <map>const int inf = 1e8;const double eps = 1e-8;const double pi = ACOs ( -1.0); template <class t> Inli      ne BOOL Rd (T &ret) {char c; int sgn;      if (C=getchar (), c==eof) return 0; while (c!= '-' && (c< ' 0 ' | |      C> ' 9 ')) C=getchar ();      sgn= (c== '-')? -1:1;      ret= (c== '-')? 0: (c ' 0 ');      while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 ');      RET*=SGN;  return 1;      } template <class t> inline void pt (T x) {if (x <0) {Putchar ('-'); x =-X;}      if (x>9) pt (X/10);  Putchar (x%10+ ' 0 '); }using namespace Std;typedef Long long ll;typedef pair<int,int> pii;const int N = 3e5+10; int gCD (int x, int y) {if (x > Y) Swap (x, y), while (x) {Y%=x;swap (x, y);} return y;} int LCM (int x, int y) {return x/gcd (x, y) * y;} int N, m;int a[n];int ans;vector<int>g[11];void dfs (int x) {if (x = = m+1) return; for (int i = 0; i < g[x].size (); i+ +) {int now = 1;for (int j = 0; J < m; j + +) if (g[x][i]& (1<<j)) now = LCM (now, A[j]); now = N/now;if (x&1) ans + = now;else ans-= now;//printf ("%d: (%d,%d)%d\n", G[x][i], x, ans, now);} DFS (x+1);} int main () {while (cin>>n>>m) {n--;for (int i = 0; i < m; i++) {rd (A[i]), if (!a[i]) i--, m--;} if (!m) {puts ("0"); continue;}  for (int i = 0; I <= m; i++) g[i].clear (); for (int i = 0; i < (1<<m); i++) {int cnt = 0, siz = I;while (siz) {cnt++; Siz &= siz-1;} G[cnt].push_back (i);} Ans = 0;dfs (1);p t (ans);    Puts (""); } return 0;}


HDU 1796 How many integers can you find (Getting Started

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.