Count a * b Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1571Accepted Submission(s): 523 Problem Description Marry likes to count the number of ways to choose two non-negative integers a and b less than m to make a×b mod m≠0 . 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 . Input The first line contains an integer T indicating the total number of test cases. Each test case is a line with a positive integer n . 1≤T≤20000 1≤n≤109 Output For each test case, print one integer s , representing g(n) modulo 264 . Sample Input
2 6 514 Sample Output
26 328194 这道题就是求 文章图片 文章图片 文章图片 文章图片 推到这一步,然后就有了一种sqrt(n)的解法 然而T=20000 于是成功卡常 参考唯一分解定理 于是现在可以先筛一个素数表 复杂度sqrt(n)以内的质数sqrt(n)/ln(n) 比上一种方法快几倍 这道题时间卡得很紧 文章图片 然而,成功爆unsigned long long 在这里, 引入__int128成功卡过 网上还有其他的防止溢出的方法
【HDU 5528 Count a × b】 |
推荐阅读
- HDU 5528【2015长春现场赛 B】 Count a * b
- 类欧几里得算法|[类欧几里得算法 数论] BZOJ 2987 Earthquake
- [数论] Codeforces 819D R #421 D.Mister B and Astronomers & 516E R #292 E. Drazil and His Happy Friends
- 模板 poj2947 Widget Factory 高斯消元
- 【扩展欧几里得】练习题
- 扩展欧几里得【数论
- 数论|hdu 5322 Hope(分治+NTT)
- 线性同余方程组
- 数论|AtCoder Beginner Contest 156 C.Rally