GCD hdu1695容斥原理
GCD
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5106 Accepted Submission(s): 1833
Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.
Yoiu can assume that a = c = 1 in all test cases.
Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
1 3 1 5 1
1 11014 1 14409 9
Case 2: 736427
For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5106 Accepted Submission(s): 1833
Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.
Yoiu can assume that a = c = 1 in all test cases.
Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
vector<int>q[];
long long a[]={};
int bb;
void init()
{
int i,j;
for(i=; i<; i++)a[i]=i,q[i].clear();
for(i=; i<; i+=)
a[i]/=,q[i].push_back();
for(i=; i<; i+=)
if(a[i]==i)
for(j=i; j<; j+=i)
a[j]=a[j]/i*(i-),q[j].push_back(i);
for(i=; i<; i++)
a[i]+=a[i-];
}
int fun(int x,int y)
{
int i,cnt=;
int sum=;
for(i=;i<q[y].size();i++)
{
if(x&(<<i))
{
sum*=q[y][i];
cnt++;
}
}
if(cnt&)
return bb/sum;
else return -(bb/sum);
}
long long work(int x)
{
int i;
long long sum=;
for(i=;i<(<<q[x].size());i++)
{
sum+=fun(i,x);
}
return bb-sum;
}
int main()
{
init();
int i,t,j,aa,c,d,k;
long long ans;
scanf("%d",&t);
for(i=; i<=t; i++)
{
scanf("%d%d%d%d%d",&aa,&bb,&c,&d,&k);
if(bb>d)swap(bb,d);
if(k)
bb/=k,d/=k;
else
{
printf("Case %d: %d\n",i,);
continue;
}
ans=a[bb];
for(j=bb+; j<=d; j++)
{
ans+=work(j);
}
printf("Case %d: %I64d\n",i,ans);
}
}
GCD hdu1695容斥原理的更多相关文章
- HDU1695:GCD(容斥原理+欧拉函数+质因数分解)好题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题目解析: Given 5 integers: a, b, c, d, k, you're to ...
- ACM学习历程—HDU1695 GCD(容斥原理 || 莫比乌斯)
Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = ...
- HDU 1695 GCD (容斥原理+欧拉函数)
题目链接 题意 : 从[a,b]中找一个x,[c,d]中找一个y,要求GCD(x,y)= k.求满足这样条件的(x,y)的对数.(3,5)和(5,3)视为一组样例 . 思路 :要求满足GCD(x,y) ...
- 2018.06.29 NOIP模拟 Gcd(容斥原理)
Gcd 题目背景 SOURCE:NOIP2015-SHY-2 题目描述 给出n个正整数,放入数组 a 里. 问有多少组方案,使得我从 n 个数里取出一个子集,这个子集的 gcd 不为 1 ,然后我再从 ...
- 51 Nod 1678 lyk与gcd(容斥原理)
1678 lyk与gcd 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 这天,lyk又和gcd杠上了. 它拥有一个n个数的数列,它想实现两种操作 ...
- HDU 4947 GCD Array 容斥原理+树状数组
GCD Array Time Limit: 11000/5500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu1695 容斥原理 莫比乌斯反演
给定两个数b,d,问[1,b]和[1,d]区间上有多少对互质的数.(x,y)和(y,x)算一个. 对于[1,b]部分,用欧拉函数直接求.对于大于b的部分,求n在[1,b]上有多少个互质的数,用容斥原理 ...
- 【bzoj4305】数列的GCD 组合数学+容斥原理
题目描述 给出一个长度为N的数列{a[n]},1<=a[i]<=M(1<=i<=N). 现在问题是,对于1到M的每个整数d,有多少个不同的数列b[1], b[2], ..., ...
- HDU1695(容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- [2014-08-24]为 Xamarin Studio 创建的 Asp.Net Mvc 项目配置 gitignore
今天在尝试 Mac 下使用 Xamarin Studio (以下简称XS) 开发 Asp.Net Mvc 项目,发现XS没启用版本控制,故自己去命令行下使用 git init,想到需要一个.gitig ...
- LVS-NAT搭建HTTP及HTTPS
author:JevonWei 版权声明:原创作品 搭建NAT模式的HTTP环境 网络拓扑图如下 网络环境 RS1 192.168.198.138 RS2 192.168.198.120 LVS: D ...
- Spring中的线程池和定时任务功能
1.功能介绍 Spring框架提供了线程池和定时任务执行的抽象接口:TaskExecutor和TaskScheduler来支持异步执行任务和定时执行任务功能.同时使用框架自己定义的抽象接口来屏蔽掉底层 ...
- 交换基本数据类型的方法swap,并影响到主方法
不知道朋友在哪里看到的问题,qq来问我,题目是:在不修改主方法的前提下使用一个方法交换两个int的值,方法如下: public static void main(String[] args) { In ...
- Linux修改文件permission属性
列出文件属性 ls -al 修改文件属性为可读.可写 sudo chmod -c 777 <your file name>
- Apache配置虚拟域名
在作php本地调试的时候,一般都要打上localhost/,如果你的项目层级关系比较多,那你的url地址就会很长. 那我们能不能用一个简短的域名去替代那些一长串无用的字符呢? 那可能有人会问如果我没有 ...
- ★10 个实用技巧,让Finder带你飞~
10 个实用技巧,让 Finder 带你飞 Finder 是 Mac 电脑的系统程序,有的功能类似 Windows 的资源管理器.它是我们打开 Mac 首先见到的「笑脸」,有了它,我们可以组织和使用 ...
- 转:Java IO流学习总结
Java流操作有关的类或接口: Java流类图结构: 流的概念和作用 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输 ...
- 验证Oracle收集统计信息参数granularity数据分析的力度
最近在学习Oracle的统计信息这一块,收集统计信息的方法如下: DBMS_STATS.GATHER_TABLE_STATS ( ownname VARCHAR2, ---所有者名字 tabname ...
- 201521123052《Java程序设计》第7周学习总结
1. 本周学习总结 参考资料: XMind 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boolean contains(Ob ...