
HDU——5528 Count a * b(积性函数推公式+唯一分解定理)
发布日期:2021-05-10 16:09:29
浏览次数:42
分类:精选文章
本文共 1653 字,大约阅读时间需要 5 分钟。
Marry likes to count the number of ways to choose two non-negative integers aa and bbless than mm to make a×ba×b mod m≠0m≠0.
Let's denote f(m)f(m) as the number of ways to choose two non-negative integers aa and bbless than mm to make a×ba×b mod m≠0m≠0. She has calculated a lot of f(m)f(m) for different mm, and now she is interested in another function g(n)=∑m|nf(m)g(n)=∑m|nf(m). For example, g(6)=f(1)+f(2)+f(3)+f(6)=0+1+4+21=26g(6)=f(1)+f(2)+f(3)+f(6)=0+1+4+21=26. She needs you to double check the answer.Input
The first line contains an integer TT indicating the total number of test cases. Each test case is a line with a positive integer nn.
1≤T≤200001≤T≤20000 1≤n≤1091≤n≤109Output
For each test case, print one integer ss, representing g(n)g(n) modulo 264264.
Sample Input
26514
Sample Output
26328194
题意:求 (|是整除,(!|)是不整除,因为不会弄这个符号) 括号(断言)里的意思是,如果i*j%x==0 返回0,否则返回1
题解:推导公式:我写了纸上了~~
请看:
化简f(m):
化简g(n):
上代码:
#include#include using namespace std;typedef long long ll;const int MAX = 1e5+10;ll p[MAX];bool vis[MAX];int cnt;void init(){//筛素数 vis[1]=vis[0]=1; for (int i = 2; i < MAX;i++){ if(!vis[i]) p[cnt++]=i; for (int j = 0; j < cnt&&i*p[j] < MAX;j++){ vis[i*p[j]]=1; if(i%p[j]==0) break; } } }int main(){ init(); int t; scanf("%d",&t); while(t--){ ll n; scanf("%lld",&n); ll ans1,ans2; ans1=ans2=1; ll w=n; for (int i = 0; p[i]*p[i]<=n;i++){//唯一分解定理 ll a,b,c; a=b=c=1; while(n%p[i]==0){ a++; b*=p[i]; n/=p[i]; c+=b*b; } ans1*=c; ans2*=a; } if(n>1){ ans1*=(n*n+1ll); ans2*=2; } printf("%lld\n",ans1-ans2*w); } return 0;}
发表评论
最新留言
感谢大佬
[***.8.128.20]2025年04月25日 15时51分09秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
MySQL:Linux下创建一个可以远端登录的账号
2021-05-10
Python 生成登录验证码图片
2021-05-10
综合架构 -- 管理服务器
2021-05-10
小程序之wx:request(转)
2021-05-10
DVWA--File Inclusion(文件包含)(全难度)
2021-05-10
实现营销号生成器
2021-05-10
Opencv视觉学习--读取、写入、显示图像
2021-05-10
linux之Shell
2021-05-10
Vue实现当前页面表格列表中的数据按时间排序sorter
2021-05-10
解决数据库报ORA-02289:序列不存在错误
2021-05-10
java实体类为什么要写.toString()方法?
2021-05-10
LINUX学习—FTP云服务器
2021-05-10
JS获取当前日期
2021-05-10
JavaScript数据类型
2021-05-11
js实现链表
2021-05-11
Vue项目中axios请求的时候使用localStorage去拼接报的401错误
2021-05-11
ArchLinux安装的各种问题(找不到磁盘、闪屏、键盘失效、声卡、网络、时间不同步)
2021-05-11
idea如何原始导入jar包
2021-05-11