[HDU5528]Count a * b
题目大意:
定义函数$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的更多相关文章
- nodejs api 中文文档
文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...
- C#中Length和Count的区别(个人观点)
这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...
- [PHP源码阅读]count函数
在PHP编程中,在遍历数组的时候经常需要先计算数组的长度作为循环结束的判断条件,而在PHP里面对数组的操作是很频繁的,因此count也算是一个常用函数,下面研究一下count函数的具体实现. 我在gi ...
- EntityFramework.Extended 实现 update count+=1
在使用 EF 的时候,EntityFramework.Extended 的作用:使IQueryable<T>转换为update table set ...,这样使我们在修改实体对象的时候, ...
- 学习笔记 MYSQL报错注入(count()、rand()、group by)
首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...
- count(*) 与count (字段名)的区别
count(*) 查出来的是:结果集的总条数 count(字段名) 查出来的是: 结果集中'字段名'不为空的记录的总条数
- 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 ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
随机推荐
- 编译caffe遇到的问题
1. failed to see hdf5.h https://askubuntu.com/questions/629654/building-caffe-failed-to-see-hdf5-h 2 ...
- php 链接转二维码图片
// 类库下载地址 https://sourceforge.net/projects/phpqrcode/files/ $value = 'www.baidu.com';//二维码内容 $errorC ...
- android中常见的Drawable资源有哪些?
Drawable资源是安卓应用中最常见的一种资源,比如图片等,因此,对于初学者而言,必须掌握drawable资源相关应用. 今天在网上刚好看到了一篇介绍android Drawable资源的文章,分享 ...
- [洛谷P3978][TJOI2015]概率论
题目大意:对于一棵随机生成的$n$个结点的有根二叉树,所有不同构的形态等概率出现(这里同构当且仅当两棵二叉树根相同,并且相同节点的左儿子和右儿子都相同),求叶子节点个数的期望是多少? 题解:令$f_n ...
- 动态规划DP的斜率优化 个人浅解 附HDU 3669 Cross the Wall
首先要感谢叉姐的指导Orz 这一类问题的DP方程都有如下形式 dp[i] = w(i) + max/min(a(i)*b(j) + c(j)) ( 0 <= j < i ) 其中,b, c ...
- code forces 996BWorld Cup
B. World Cup time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- bzoj1266 [AHOI2006]上学路线route floyd+最小割
1266: [AHOI2006]上学路线route Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 2490 Solved: 898[Submit][S ...
- Android 自定义动画 Loading
转自:http://my.oschina.net/janson2013/blog/118558 1.定义一个ImageView 定义一个ImageView是为了装载图片,其中的图片将被rotate用来 ...
- css字体投影
最近在整理学习CSS3的一些小知识,现在已经整理了CSS3选择器,CSS3圆角和CSS3元素阴影属性的使用方法了.今天为大家整理一下CSS3中的文字阴影——text-shadow的使用方法.希望能对大 ...
- 第18章 Active控件
转自: https://blog.csdn.net/u014162133/article/details/46573873 容器和服务器程序 容器应用程序时可以嵌入或链接对象的应用程序.Word就是容 ...