题目描述

Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He has alreadyfound out that whilst deciphering a message he will have to answer multiple queries of the form"for givenintegers  and , find the number of integer pairs  satisfying the following conditions:

,,, where  is the greatest common divisor of  and ".

Byteasar would like to automate his work, so he has asked for your help.

TaskWrite a programme which:

reads from the standard input a list of queries, which the Byteasar has to give answer to, calculates answers to the queries, writes the outcome to the standard output.

FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d。作为FGD的同学,FGD希望得到你的帮助。

输入输出格式

输入格式:

The first line of the standard input contains one integer  (),denoting the number of queries.

The following  lines contain three integers each:  and (), separated by single spaces.

Each triplet denotes a single query.

输出格式:

Your programme should write  lines to the standard output. The 'th line should contain a single integer: theanswer to the 'th query from the standard input.

输入输出样例

输入样例#1:

  1. 2
  2. 4 5 2
  3. 6 4 3
输出样例#1:

  1. 3
  2. 2
    题解:莫比乌斯反演+分块
    其实我写过一边博客上的题跟这个几乎一摸一样,而且这个还不要容斥
    在这里偷个懒,贴出题目 [HAOI2011]Problem b
    本题卡常数,所以能不用long long就不用
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. using namespace std;
  6. typedef long long lol;
  7. lol ans;
  8. int prime[];
  9. lol mu[];
  10. int n,m,d,tot;
  11. bool vis[];
  12. void mobius()
  13. {int i,j;
  14. mu[]=;
  15. for (i=;i<=;i++)
  16. {
  17. if (vis[i]==)
  18. {
  19. tot++;
  20. prime[tot]=i;
  21. mu[i]=-;
  22. }
  23. for (j=;j<=tot,i*prime[j]<=;j++)
  24. {
  25. vis[i*prime[j]]=;
  26. if (i%prime[j]==)
  27. {
  28. mu[i*prime[j]]=;
  29. break;
  30. }
  31. mu[i*prime[j]]=-mu[i];
  32. }
  33. }
  34. for (i=;i<=;i++)
  35. mu[i]+=mu[i-];
  36. }
  37. void solve()
  38. {int i;
  39. int pos=;
  40. int r=min(n,m);
  41. for (i=;i<=r;i=pos+)
  42. {
  43. if (n/(n/i)>m/(m/i))
  44. pos=m/(m/i);
  45. else pos=n/(n/i);
  46. ans+=(mu[pos]-mu[i-])*(long long)(n/i)*(long long)(m/i);
  47. }
  48. }
  49. int main()
  50. {int T;
  51. cin>>T;
  52. mobius();
  53. while (T--)
  54. {
  55. scanf("%d%d%d",&n,&m,&d);
  56. n=n/d;m=m/d;
  57. ans=;
  58. solve();
  59. printf("%lld\n",ans);
  60. }
  61. }

[POI2007]ZAP-Queries的更多相关文章

  1. BZOJ 1101: [POI2007]Zap

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2262  Solved: 895[Submit][Status] ...

  2. [BZOJ1101][POI2007]Zap

    [BZOJ1101][POI2007]Zap 试题描述 FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd ...

  3. BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )

    求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...

  4. BZOJ1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2951  Solved: 1293[Submit][Status ...

  5. 莫比乌斯反演学习笔记+[POI2007]Zap(洛谷P3455,BZOJ1101)

    先看一道例题:[POI2007]Zap BZOJ 洛谷 题目大意:$T$ 组数据,求 $\sum^n_{i=1}\sum^m_{j=1}[gcd(i,j)=k]$ $1\leq T\leq 50000 ...

  6. [POI2007]Zap

    bzoj 1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Descriptio ...

  7. Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...

  8. BZOJ1101 POI2007 Zap 【莫比乌斯反演】

    BZOJ1101 POI2007 Zap Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b, ...

  9. 1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...

  10. 【BZOJ】1101: [POI2007]Zap(莫比乌斯+分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1101 无限膜拜数论和分块orz 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...

随机推荐

  1. Week03-面向对象入门

    1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词,如类.对象.封装等 类 对象 封装 继承 覆盖 重载 构造函数 static public private toString f ...

  2. highcharts 具体参数详解

    <script type="text/javascript" src="js/jquery.min.js"></script> < ...

  3. 第二篇:利用shell脚本执行webservice请求——基于soap

    1. 项目背景 以往我们在开发基于webservice的项目中,我们总习惯于直接使用webservice的一些框架,如Axis,axis2和Xfire等.框架的好处是将webservice所涉及到的s ...

  4. windows 10下通过python3.6成功搭建jupyter 服务器

    最近通过python学习爬虫技术,发现一个工具jupyter notebook很不错,该工具明显优势通过浏览器可以输入多行python代码,支持在线运行以及运行结果保存功能,在线验证python小模块 ...

  5. 彻底搞懂shell的高级I/O重定向

    本文目录: 1.1 文件描述符(file description,fd) 1.2 文件描述符的复制 1.3 重定向顺序很重要:">file 2>&1"和&quo ...

  6. Python扩展模块——selenium的使用(定位、下载文件等)

    想全面的使用selenium可以下载<selenium 2自动化测试实战-基于Python语言>PDF的电子书看看 我使用到了简单的浏览器操作,下载文件等功能... 推荐使用firefox ...

  7. 查找git ignore的追踪

    前言 版本控制说简单也简单,说复杂也困难的多.作为开发者,最基础的版本管理和团队协作的功能必须掌握.而其他一些相关的信息也可以了解下.比如,这次就有同事遇到了问题. 遇到的问题 在windows下,往 ...

  8. emqtt 试用(六)系统主题

    $SYS-系统主题 EMQ 消息服务器周期性发布自身运行状态.MQTT 协议统计.客户端上下线状态到 $SYS/ 开头系统主题. $SYS 主题路径以 "$SYS/brokers/{node ...

  9. Spring知识点回顾(06)Profile 和 条件注解 @Conditional

    1.设定环境中的active profiles 如:DispatcherServerlet的init-param spring.profiles.active=production spring.pr ...

  10. python、java实现二叉树,细说二叉树添加节点、深度优先(先序、中序、后续)遍历 、广度优先 遍历算法

    数据结构可以说是编程的内功心法,掌握好数据结构真的非常重要.目前基本上流行的数据结构都是c和c++版本的,我最近在学习python,尝试着用python实现了二叉树的基本操作.写下一篇博文,总结一下, ...