HDU_5528_Count a * b
Count a * b
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 872 Accepted Submission(s): 315
Let's denote f(m) as the number of ways to choose two non-negative integers a and b less than m to make a×b mod m≠0.
She has calculated a lot of f(m) for different m, and now she is interested in another function g(n)=∑m|nf(m). For example, g(6)=f(1)+f(2)+f(3)+f(6)=0+1+4+21=26. She needs you to double check the answer.

Give you n. Your task is to find g(n) modulo 264.
1≤T≤20000
1≤n≤109
6
514
328194
- 要推公式啊,贴过程:



- 注:
- (1)后半个公式可以看做对于变量a在整数意义上的划分,之后再进行gcd结果的加和。这里对于划分变量的方式有改进的余地,可以根据gcd结果进行划分。考虑gcd(x,a)|x,所以用x的因数对gcd结果进行划分,而且最好用Dirichlet的形式进行改进,毕竟gcd和常函数都是积性函数,Dirichlet形式下的新函数保持积性函数的性质,利于简化计算。
- (2)对于f(x)的化简结果,考虑带入g(n)有进一步化简的可能
- (3)考虑整除的传递性,这里如果可以把变量x消去是最好的。我们这里先枚举d,再找x,之后用i代替x/d,i*d|n,其中i*d==x,根据整除性质不难得到i|(d/n),那么就看到一个很熟悉的公式,后半公式就是对于n求全部因数的欧拉函数,结果就是n本身
- (4)最终结果
- (5)把因数k次方和理解成多项式相乘处理是有一定好处的,好处在于没有对于除法的处理,全都是简单的加法和乘法,这对于取模运算是一大福音。此外,考虑到因数k次方函数是积性函数,也可以先对n分解质因数之后分步求解,但是这里就要对于每一个质因数的乘方做等比数列求和,牵扯到除法,对应的在代码中要做防溢出操作(好吧,我这个鶸是不会这种骚操作的QAQ)
- 至于说题目里对于2^64取模就是在unsigned longlong下运算就ok
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; ULL T, n, prime[maxn], nd, theta2;
bool vis[maxn];
int tot, cnt;
void init(int top){
tot=;
memset(vis,true,sizeof(vis));
for(int i=;i<=top;i++){
if(vis[i]){
prime[tot++]=(ULL)i;
}
for(int j=;j<tot&&(i*prime[j]<=top);j++){
vis[i*prime[j]]=false;
if(i%prime[j]==)
break;
}
}
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
init(1e5+);
while(~scanf("%llu",&T)){
while(T--){
scanf("%llu",&n);
theta2=1ULL;
nd=n;
for(int i=;i<tot && prime[i]*prime[i]<=n;i++)
if(n%prime[i]==){
ULL p=prime[i], alpha=0ULL;
ULL sigma=1ULL, square=1ULL;
while(n%p==0ULL){
alpha++;
square*=p;
sigma+=square*square;
n/=p;
}
nd*=alpha+1ULL;
theta2*=sigma;
}
if(n>){
nd*=2ULL;
theta2*=(1ULL+n*n);
}
printf("%llu\n",theta2-nd);
}
}
return ;
}
HDU_5528_Count a * b的更多相关文章
随机推荐
- Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed.
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nes ...
- VTK使用矢量数据弯曲几何体
vtkWarpVector is a filter that modifies point coordinates by moving points along vector times the sc ...
- kafka注册异常
问题描述: kafka注册异常,提示brokers id已经被注册过 -- ::,] FATAL [Kafka Server ], Fatal error during KafkaServer sta ...
- Android获取通讯录并上传(包含通讯录加密)
好久没更新文章了,近期在做通讯录上传,把它分享出来,送给需要的朋友. 写了一个通讯录工具类,直接放代码吧,关键位置通过注释来解释. 这个工具类包含通讯录获取,加密,然后上传操作.看不懂的可以留言 im ...
- 如何快速申请苹果IOS个人开发者账号
在上周我有一同事,他利用周末的时间自己做了一个IOS版本游戏类APP,用Unity3D开发的(抱着好玩的心态),于是他想发布到苹果App Store 上去.他没有苹果开发者账号,也没有购买过. 于是找 ...
- 【C++】C++中变量的声明与定义的区别
声明(declaration):意味着告诉编译器关于变量名称.变量类型.变量大小.函数名称.结构名称.大小等等信息,并且在声明阶段不会给变量分配任何的内存. 定义(definition):定义就是在变 ...
- Kettle实现数据抽取、转换、装入和加载数据-数据转移ETL工具
原文地址:http://www.xue51.com/soft/5341.html Kettle是来自国外的一款开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,绿色无需 ...
- inode满引发不能写文件的问题
一.引言: 二.文件解决: 三.inode概念: 四.尾声:
- SNF软件开发机器人-子系统-功能-数据列表分页与不分页-瀑布式分页-如何配置?
[列表]分页 1.效果展示: (1)不分页 (2)普通分页 (3)瀑布式分页 2.使用说明: 打开显示页面,点击开发者选项的简单配置按钮.在功能表信息中选择需要的分页方式.普通分页和瀑布式分页需要配合 ...
- ComputeShader中Consume与AppendStructuredBuffer的使用
上个月写了一篇使用像素shader返回累加信息的Trick:https://www.cnblogs.com/hont/p/9977401.html 后来无意中发现DX11/Compute shader ...