Hdu1695 GCD 2017-06-27 22:19 30人阅读 评论(0) 收藏
GCD
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11177 Accepted Submission(s): 4236
pairs.
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.
2
1 3 1 5 1
1 11014 1 14409 9
Case 1: 9
Case 2: 736427HintFor 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<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define LL long long
const int inf=0x3f3f3f3f; vector<LL>p[100010];
int pr[100010];
int a,b,x,y,k;
LL ans; void init()
{
memset(pr,0,sizeof pr);
for(int i=1;i<=100005;i++) p[i].clear();
for(int i=2;i<=100005;i+=2)
p[i].push_back(2);
for(int i=3;i<=100005;i+=2)
{
if(!pr[i])
{
for(int j=i;j<=100005;j+=i)
{
pr[j]=1;
p[j].push_back(i);
} }
}
} void dfs(int no,int pos,int xx,int cnt)
{
if(pos>=p[no].size())
{
if(cnt==0)
return;
if(cnt%2)
{
ans+=y/xx;
ans-=(no-1)/xx;
}
else
{
ans-=y/xx;
ans+=(no-1)/xx;
}
return;
}
dfs(no,pos+1,xx*p[no][pos],cnt+1);
dfs(no,pos+1,xx,cnt);
} int main()
{
init();
int T;
int q=1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d%d",&a,&x,&b,&y,&k);
if (k == 0) {
printf("Case %d: 0\n", q++);
continue;
}
x/=k,y/=k;
if(x>y) swap(x,y);
LL ans2=0;
for(int i=1; i<=x; i++)
{
ans=0;
dfs(i,0,1,0);
ans2+=y-i+1-ans;
}
printf("Case %d: %lld\n",q++,ans2);
}
return 0;
}
Hdu1695 GCD 2017-06-27 22:19 30人阅读 评论(0) 收藏的更多相关文章
- NYOJ-206 矩形的个数 AC 分类: NYOJ 2013-12-29 22:19 265人阅读 评论(0) 收藏
这题目是小学奥数题目,方法可以百度到,但是,有个难点就是,数据类型大小不够,如果是1000x1000的矩阵,那么就会超过int的范围,所以,就引进了long long的数据类型 #include< ...
- NYOJ-469 擅长排列的小明 II AC 分类: NYOJ 2014-01-02 22:19 159人阅读 评论(0) 收藏
最初的第一印象是和组合数一个性质的题目.所以用了回溯法,结果,你懂的... #include<stdio.h> #include<math.h> void dfs(int n, ...
- Poj2231 Moo Volume 2017-03-11 22:58 30人阅读 评论(0) 收藏
Moo Volume Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22104 Accepted: 6692 Descr ...
- 全方位分析Objcetive-C Runtime 分类: ios技术 2015-03-11 22:29 77人阅读 评论(0) 收藏
本文详细整理了 Cocoa 的 Runtime 系统的知识,它使得 Objective-C 如虎添翼,具备了灵活的动态特性,使这门古老的语言焕发生机.主要内容如下: 引言 简介 与Runtime交互 ...
- Hdu2068 RPG的错排 2017-06-27 15:27 30人阅读 评论(0) 收藏
RPG的错排 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
- android开发之this.finish()的使用 分类: android 学习笔记 2015-07-18 19:05 30人阅读 评论(0) 收藏
在一个Activity用完之后应该将之finish掉,但是,之前在学校里自己摸索着开发时并没有太注意这个问题,因为activity无论是否finish掉对功能的影响貌似都不是那么明显(这是读书时候的观 ...
- java面试和笔试大全 分类: 面试 2015-07-10 22:07 10人阅读 评论(0) 收藏
2.String是最基本的数据类型吗? 基本数据类型包括byte.int.char.long.float.double.boolean和short. java.lang.String类是final类型 ...
- Struts知识问答 分类: 面试 2015-07-10 22:01 4人阅读 评论(0) 收藏
1. 简述Struts框架的初始化流程. 答案: 对于采用Struts框架的Web应用,在Web应用启动时就会加载并初始化控制器ActionServlet ActionServlet从struts-c ...
- Work around by " Due to heavy load, the latest workflow operation has been queued. " 分类: Sharepoint 2015-07-08 00:19 3人阅读 评论(0) 收藏
I hope most of the users and developers might have come across above note and worried about it. Ther ...
随机推荐
- Android.PublishApplication
发布应用 3. 为App签名 Android 要求App在安装前,需要使用证书(certificate)来进行数字签名(be digitally signed). Android 用证书来标识一个Ap ...
- Redhat Linux网卡配置与绑定
Redhat Linux的网络配置,基本上是通过修改几个配置文件来实现的,虽然也可以用ifconfig来设置IP,用route来配置默认网关,用hostname来配置主机名,但是重启后会丢失. 相关的 ...
- spring配置遇到的问题
1.文档根元素 "beans" 必须匹配 DOCTYPE 根 "null" 这个原因是因为我自动扫描mapping.xml的文件路径设置错误,把它设置成spri ...
- padding属性
p {padding:2cm 4cm 3cm 4cm;} 属性定义及使用说明 padding简写属性在一个声明中设置所有填充属性.该属性可以有1到4个值. 实例: 填充:10px 5px 15px 2 ...
- CreateToolhelp32Snapshot 以及 EnumProcesses
RT,请教如何获得Windows任务管理器中所显示的进程列表. CreateToolhelp32Snapshot 以及 EnumProcesses 这些方法我都试过了,但是这两种方法得到的结果和任务管 ...
- Squares of a Sorted Array LT977
Given an array of integers A sorted in non-decreasing order, return an array of the squares of each ...
- proguard-rules.pro、混淆、导jar包
前记: 买了一个<精通Android Studio>本来最想看的是关于混淆导jar包的,哪知道没有,有点小失望. 好吧,自己来. 在用Android Studio开发的时候,把minify ...
- base64编码是什么1
首先明确一点base64 是一种编码格式.就想UNICODE一样,能在电脑上表示所有字符,或者换句话说通过编码能让电脑理解你想要表示的字符(因为电脑只知道0和1 ) 就像ascII 中 0100 00 ...
- 搭建java环境和java学习
https://blog.csdn.net/fishe_r/article/details/18863447 其中的 java配置文件用: { "shell_cmd": " ...
- import this
import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than ...