hdu 1796 How many integers can you find
容斥原理!!
这题首先要去掉=0和>=n的值,然后再使用容斥原理解决
我用的是数组做的……
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#define ll __int64
using namespace std;
int an[],n,m,num,a[];
ll gcd(int a,int b)
{
int t;
if(a<b) swap(a,b);
while(b)
{
t=a;
a=b;
b=t%b;
}
return a;
}
ll lcm(int a,int b)
{
return a/gcd(a,b)*b;
}
ll cal()
{
ll quene[],sum=;
int t=,k,i,j;
quene[t++]=-;
for(i=;i<num;i++)
{
k=t;
for(j=;j<k;j++)
{
if(quene[j]<)
quene[t++]=lcm(-quene[j],an[i]);
else quene[t++]=(-)*lcm(quene[j],an[i]);
}
}
for(i=;i<t;i++)
sum+=(n-)/quene[i];
return sum;
}
int main()
{
int i,j,t,k;
while(cin>>n>>m)
{
num=;k=;
for(i=;i<m;i++)
{
cin>>t;
if(t>&&t<n) an[num++]=t;
}
printf("%I64d\n",cal());
}
return ;
}
hdu 1796 How many integers can you find的更多相关文章
- HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举)
HDU.1796 How many integers can you find ( 组合数学 容斥原理 二进制枚举) 题意分析 求在[1,n-1]中,m个整数的倍数共有多少个 与 UVA.10325 ...
- HDU 1796 How many integers can you find (状态压缩 + 容斥原理)
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...
- HDU 1796 How many integers can you find(容斥原理)
题目传送:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=20918&pid=1002 Problem Description ...
- HDU 1796 How many integers can you find 容斥入门
How many integers can you find Problem Description Now you get a number N, and a M-integers set, y ...
- 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(容斥原理+二进制/DFS)
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 【容斥】
<题目链接> 题目大意: 给你m个数,其中可能含有0,问有多少小于n的正数能整除这个m个数中的某一个. 解题分析: 容斥水题,直接对这m个数(除0以外)及其组合的倍数在[1,n)中的个数即 ...
随机推荐
- RSS 订阅
<?xml version="1.0"?><%@ Page Language="C#" AutoEventWireup="true& ...
- TextEdit验证
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using ...
- linux编程:环境表
每个进程在启动的时候都会收到一张环境表.环境表是由一个字符指针数组组成,每个指针包含一个以NULL结束的字符串的地址,全局变量environ包含了指针数组的地址: extern char **envi ...
- WPF 绑定一(数据源为控件)
xaml: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.co ...
- table总结insertRow、deleteRow
表格有几行: var trCnt = table.rows.length; (table为Id ) 每行有几列:for (var i=0; i<trCnt; i++) ...
- linux服务器git pull/push时提示输入账号密码之免除设置
1.先cd到根目录,执行git config --global credential.helper store命令 [root@iZ25mi9h7ayZ ~]# git config --global ...
- IIS6下, web.config配置为targetFramework="4.0"时出404错误
打开IIS管理器,在"Web 服务扩展" 中 将ASP.NET v4.0设置为允许就好了.这个选项默认是禁止的.
- 5、WPF实现简单计算器-非常适合初学者练习
Sample Calculator 这是微软社区WPF的一个示例,在源程序的基础上我进行了一点点修改,非常适合初学者练习,详细代码解释. 源程序的下载地址 http://code.msdn.micro ...
- 1049. Counting Ones/整数中1出现的次数(从1到n整数中1出现的次数)
The task is simple: given any positive integer N, you are supposed to count the total number of 1's ...
- TIME_WAIT引起Cannot assign requested address报错
1. 问题描述 有时候用redis客户端(php或者java客户端)连接Redis服务器,报错:"Cannot assign requested address." 原因是客户端 ...