题目大意:
  定义函数$f(m)=\displaystyle\sum_{a=0}^{m-1}\sum_{b=0}^{m-1}[m\nmid ab]$,$g(n)=\displaystyle\sum_{m\mid n}f(m)$。
  共有$q(q\leq2\times10^4)$次询问,每次询问$g(n)(n\leq10^9)$的值。

思路:
  对$n$分解质因数,得$n=\displaystyle\prod_{i=1}^rp_i^{q_i}$。
  推公式得$g(n)=\displaystyle\prod_{i=1}^r\frac{(p_i^{q_i+1})-1}{p_i^2-1}-n\prod_{i=1}^r(q_i+1)$。
  先预处理出质数表,然后暴力分解质因数即可。

 #include<cstdio>
#include<cctype>
typedef unsigned long long qword;
typedef unsigned __int128 oword;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int M=,SIZE=;
bool b[M];
int p[SIZE];
inline void init() {
for(register int i=;i<M;i++) {
if(!b[i]) {
p[++p[]]=i;
for(register int j=i*;j<M;j+=i) {
b[j]=true;
}
}
}
}
int main() {
init();
const int T=getint();
for(register int t=;t<=T;t++) {
int n=getint();
qword prod1=,prod2=n;
for(register int i=;p[i]*p[i]<=n;i++) {
if(n%p[i]!=) continue;
int q=;
qword tmp=p[i];
while(n%p[i]==) {
n/=p[i];
tmp*=p[i];
q++;
}
prod2*=q+;
prod1*=((oword)tmp*tmp-)/(p[i]*p[i]-);
}
if(n!=) {
prod1*=(qword)n*n+;
prod2*=;
}
printf("%llu\n",prod1-prod2);
}
return ;
}

[HDU5528]Count a * b的更多相关文章

  1. nodejs api 中文文档

    文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...

  2. C#中Length和Count的区别(个人观点)

    这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...

  3. [PHP源码阅读]count函数

    在PHP编程中,在遍历数组的时候经常需要先计算数组的长度作为循环结束的判断条件,而在PHP里面对数组的操作是很频繁的,因此count也算是一个常用函数,下面研究一下count函数的具体实现. 我在gi ...

  4. EntityFramework.Extended 实现 update count+=1

    在使用 EF 的时候,EntityFramework.Extended 的作用:使IQueryable<T>转换为update table set ...,这样使我们在修改实体对象的时候, ...

  5. 学习笔记 MYSQL报错注入(count()、rand()、group by)

    首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...

  6. count(*) 与count (字段名)的区别

    count(*) 查出来的是:结果集的总条数 count(字段名) 查出来的是: 结果集中'字段名'不为空的记录的总条数

  7. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  8. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  9. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

随机推荐

  1. NodeJs04

    REST API的设计 前言 客户端通过请求URL,传递参数,去获取指定的数据,这就是API(ApplicationProgramInterface). API是前端和客户端操作后端数据的一种方式,一 ...

  2. HDU 4763 Theme Section ( KMP next函数应用 )

    设串为str, 串长为len. 对整个串求一遍next函数,从串结尾开始顺着next函数往前找<=len/3的最长串,假设串长为ans,由于next的性质,所以找到的串肯定满足E……E这种形式, ...

  3. JavaWeb笔记(三)HTTP

    常见请求头 User-Agent:浏览器版本信息,可以解决浏览器兼容性问题 Referer:请求来源地址,可以防盗链和统计 Request 方法 获取请求方式: String getMethod() ...

  4. 洛谷 最小费用最大流 模板 P3381

    #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #defi ...

  5. 叶落归根(hometown)

    叶落归根(hometown) 题目描述 叶落归根——树叶从树根生发出来,凋落后最终还是回到树根.比喻事物总有一定的归宿.接下来是题目. 给定一个n个点的有向图G(点的编号为1~n),一开始落叶(仅作为 ...

  6. poj 3648 Wedding 2-SAT问题入门题目

    Description Up to thirty couples will attend a wedding feast, at which they will be seated on either ...

  7. 转载~Linux 平台下阅读源码的工具

    Linux 平台下阅读源码的工具 前言 看源代码是一个程序员必须经历的事情,也是可以提升能力的一个捷径.个人认为: 要完全掌握一个软件的方法只有阅读源码在Windows下有sourceinsight这 ...

  8. 割点与桥,强连通分量,点双,边双[poj_1236]学校网络

    割点与桥 题目描述 给定一张无向图G(V,E),你需要找出所有的割点与桥. 输入 第一行给出两个正整数V,E. 接下来E行每行两个正整数x,y,表示有一条连接x,y的边. 输出 输出共2行,第一行输出 ...

  9. QML与C++混合编程详解

    1.QML与C++为什么要混合编程 QML与C++为什么要混合编程,简单来说,就是使用QML高效便捷地构建UI,而C++则用来实现业务逻辑和复杂算法,下面介绍了两者间交互的方法与技巧. 2.QML访问 ...

  10. 最简单的基于FFmpeg的AVDevice例子(读取摄像头)【转】

    转自:http://blog.csdn.net/leixiaohua1020/article/details/39702113 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[- ...