HDU How many integers can you find 容斥
How many integers can you find
Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4249 Accepted Submission(s):
1211
should find out how many integers which are small than N, that they can divided
exactly by any integers in the set. For example, N=12, and M-integer set is
{2,3}, so there is another set {2,3,4,6,8,9,10}, all the integers of the set can
be divided exactly by 2 or 3. As a result, you just output the number 7.
line contains two integers N and M. The follow line contains the M integers, and
all of them are different from each other. 0<N<2^31,0<M<=10, and the
M integer are non-negative and won’t exceed 20.
2 3
略坑略坑。
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; bool Hash[];
int f[],len,qlen;
__int64 Q[]; int gcd(int a,int b)
{
if(a<)a=-a;
if(b<)b=-b;
if(b==)return a;
int r;
while(b)
{
r=a%b;
a=b;
b=r;
}
return a;
}
void solve(__int64 m)
{
qlen = ;
Q[]=-;
for(int i=;i<=len;i++)
{
int k=qlen;
for(int j=;j<=k;j++)
Q[++qlen]=-*(Q[j]*f[i]/gcd(Q[j],f[i]));
}
__int64 sum = ;
for(int i=;i<=qlen;i++)
sum = sum+m/Q[i];
printf("%I64d\n",sum);
}
int main()
{
int m,x;
__int64 n;
while(scanf("%I64d%d",&n,&m)>)
{
n=n-;
memset(Hash,false,sizeof(Hash));
for(int i=;i<=m;i++)
{
scanf("%d",&x);
Hash[x]=true;
}
for(int i=;i<=;i++)
{
if(Hash[i]==true)
for(int j=i+i;j<=;j=j+i)
if(Hash[j]==true) Hash[j]=false;
}
len = ;
for(int i=;i<=;i++)if(Hash[i]==true) f[++len]=i;
solve(n);
}
return ;
}
HDU How many integers can you find 容斥的更多相关文章
- hdu 1796 How many integers can you find 容斥定理
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 1796 How many integers can you find 容斥第一题
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1796 How many integers can you find (容斥)
题意:给定一个数 n,和一个集合 m,问你小于的 n的所有正数能整除 m的任意一个的数目. 析:简单容斥,就是 1 个数的倍数 - 2个数的最小公倍数 + 3个数的最小公倍数 + ...(-1)^(n ...
- How many integers can you find(容斥+dfs容斥)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- hdu 6169 Senior PanⅡ Miller_Rabin素数测试+容斥
Senior PanⅡ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Pr ...
- HDU - 5297:Y sequence (迭代&容斥)
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hat ...
- Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- HDU - 4336:Card Collector(min-max容斥求期望)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- HDU - 5977 Garden of Eden (树形dp+容斥)
题意:一棵树上有n(n<=50000)个结点,结点有k(k<=10)种颜色,问树上总共有多少条包含所有颜色的路径. 我最初的想法是树形状压dp,设dp[u][S]为以结点u为根的包含颜色集 ...
随机推荐
- C++新手之培养良好的编程风格
内功深厚的武林高手出招往往平淡无奇.同理,编程高手也不会用奇门怪招写程序.良好的编程风格是产生高质量程序的前提. 下面以C++为例,来给大家介绍. 一. 命名约定 有不少人编程时用拼音给函数或变量命名 ...
- 从一个例子讲解拷贝构造函数与return
#include "iostream" using namespace std; class Location { public: Location(, ) { X = xx; Y ...
- 侧菜单栏的实现SlidingPaneLayout
SlidingPaneLayout分为两部分,上面的 左划出部分和没划出的时候 <?xml version="1.0" encoding="utf-8"? ...
- Socket get http request
package wuyubao.firstsample; import java.io.BufferedReader; import java.io.IOException; import java. ...
- git批量删除分支
要删除本地,首先要考虑以下三点 列出所有本地分支 搜索目标分支如:所有含有'dev'的分支 将搜索出的结果传给删除函数 所以我们可以得到: git br |grep 'dev' |xargs git ...
- php类与对象简单操作
<?php /* * Created on 2015-8-25 * * To change the template for this generated file go to * Window ...
- jquery遍历对象,数组,集合
1.jquery 遍历对象 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTM ...
- 夺命雷公狗---DEDECMS----8dedecms干掉首页和-文档页-栏目页的页面的广告
我们首先来将首页生成静态页面,如下图所示: 成功后,如下显示: 如果成功后则在文件夹下多了一个index.html的文件.. 我们的首页静态页面是通过模版文件生成,所以我们只需要把模版文件的广告标签删 ...
- Spring+SpringMVC+MyBatis)
用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没有记录SSM整合的 ...
- Android横竖屏切换继续播放视频
只需要重新onSaveInstanceState方法,在其里面记住我们要记录的参数 package com.bawei.day07_videoview; import android.os.Bundl ...