数学--数论--HDU 5382 GCD?LCM?(详细推导,不懂打我)
Describtion
First we define:
(1) lcm(a,b), the least common multiple of two integers a and b, is the smallest positive integer that is divisible by both a and b. for example, lcm(2,3)=6 and lcm(4,6)=12.
(2) gcd(a,b), the greatest common divisor of two integers a and b, is the largest positive integer that divides both a and b without a remainder, gcd(2,3)=1 and gcd(4,6)=2.
(3) [exp], exp is a logical expression, if the result of exp is true, then [exp]=1, else [exp]=0. for example, [1+2≥3]=1 and [1+2≥4]=0.
Now Stilwell wants to calculate such a problem:
F(n)=∑i=1n∑j=1n [ lcm(i,j)+gcd(i,j)≥n ]S(n)=∑i=1nF(i)
Find S(n) mod 258280327.
Input
The first line of the input contains a single number T, the number of test cases.
Next T lines, each line contains a positive integer n.
T≤105, n≤106.
Output
T lines, find S(n) mod 258280327.
Sample Input
8
1
2
3
4
10
100
233
11037
Sample Output
1
5
13
26
289
296582
3928449
213582482
推导详细



强烈建议:不赞成网上像我前面的因素和求Q(N),这里的先求因子个数再用快速幂求解,但是这里的不同因子个数恰好可以用线性筛求解,但是在其余题目中不一定恰好可以使用,应该使用积性函数的性质直接使用线性筛,这样时间复杂度上少了一个快速幂。
好久没用scanf, printf 超时,然后写上了,忘了换行,题解叫上过来,我的就一直wa,写了对拍也是对的,我都懵了,感叹造化弄人的时候,一点一点用标程替换,知道吧printf换掉我就明白了,我太难了,凌晨1.30了,还满怀兴奋。睡不着。
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1010010;
bool vis[mxn];
long long pri[100000], G[mxn], tot;
long long low[mxn];
long long T[mxn], F[mxn], S[mxn];
//线性筛求解G[]
void shai()
{
tot = 1;
memset(vis, 0, sizeof(vis));
low[1] = 1;
G[1] = 1;
for (int i = 2; i <= mxn; i++)
{
if (!vis[i])
{
pri[tot++] = i;
low[i] = i;
G[i] = 2;
}
for (int j = 1; j <= tot && pri[j] * i <= mxn; j++)
{
vis[i * pri[j]] = 1;
if (i % pri[j] == 0) //不互质
{
low[i * pri[j]] = low[i] * pri[j];
if (i == low[i]) //p^K次幂,由递推求解
G[i * pri[j]] = 2;
//p^k只能拆成 1 *p^k 和p^k * 1其余的情况不GCD不等于1
else
G[i * pri[j]] = G[i / low[i]] * G[pri[j] * low[i]];
break;
}
low[i * pri[j]] = pri[j];
G[i * pri[j]] = G[i] * G[pri[j]];
}
}
}
void go()
{
//因数枚举求解T,这里的枚举是一个很好用的技巧
memset(T, 0, sizeof(T));
for (int i = 1; i <= mxn; i++)
{
for (int j = i; j <= mxn; j += i)
{
T[j] = (T[j] + G[j / i - 1]) % 258280327;
}
}
//递推求F,S
S[1] = F[1] = 1;
for (int i = 2; i <= mxn; i++)
{
F[i] = (((F[i - 1] + 2 * i - 1) % 258280327 - T[i - 1]) % 258280327 +258280327) % 258280327;
S[i] = (S[i - 1] + F[i]) % 258280327;
//cout << i << " " << S[i] << endl;
}
}
int main()
{
shai();
go();
int t;
cin >> t;
while (t--)
{
int k;
scanf("%d", &k);
printf("%lld\n", S[k]);
}
return 0;
}
数学--数论--HDU 5382 GCD?LCM?(详细推导,不懂打我)的更多相关文章
- 2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5382 题意:函数lcm(a,b):求两整数a,b的最小公倍数:函数gcd(a,b):求两整数a,b的最 ...
- hdu 5382 GCD?LCM! - 莫比乌斯反演
题目传送门 传送门I 传送门II 题目大意 设$F(n) = \sum_{i = 1}^{n}\sum_{j = 1}^{n}\left [ [i, j] + (i, j) \geqslant n \ ...
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- 数学--数论--HDU 5223 - GCD
Describtion In mathematics, the greatest common divisor (gcd) of two or more integers, when at least ...
- hdu 5382 GCD?LCM!
先考虑化简f函数 发现,f函数可以写成一个递归式,化简后可以先递推求出所有f函数的值, 所以可以先求出所有S函数的值,对于询问,O(1)回答 代码: //File Name: hdu5382.cpp ...
- 数论入门2——gcd,lcm,exGCD,欧拉定理,乘法逆元,(ex)CRT,(ex)BSGS,(ex)Lucas,原根,Miller-Rabin,Pollard-Rho
数论入门2 另一种类型的数论... GCD,LCM 定义\(gcd(a,b)\)为a和b的最大公约数,\(lcm(a,b)\)为a和b的最小公倍数,则有: 将a和b分解质因数为\(a=p1^{a1}p ...
- 数学--数论--HDU 5019 revenge of GCD
Revenge of GCD Problem Description In mathematics, the greatest common divisor (gcd), also known as ...
- 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)
Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...
- hdu 5584 gcd/lcm/数学公式
input T 1<=T<=1000 x y output 有多少个起点可以走n(n>=0)步走到(x,y),只能从(x,y)走到(x,y+lcm(x,y))/(x+lcm(x,y) ...
随机推荐
- django->model模型操作(数据库操作)
一.字段类型 二.字段选项说明 三.内嵌类参数说明abstract = Truedb_table = 'table_name' #表名,默认的表名是app_name+类名ordering = ['id ...
- CH5105 Cookies (线性dp)
传送门 解题思路: 贪心的想,贪婪值越大的孩子应该分得更多的饼干,那么先sort一遍在此基础上进行dp.最直观的方向,可以设dp[i][j]为前i个孩子一共分得j块饼干的怨恨最小值.然后转移第i+1个 ...
- 新手必须知道的13个Xcode小技巧
当谈论到iOS开发工具时,有一个肯定是所有iOS开发者都熟悉的,那就是Xcode.Xcode是使所有令人赞叹的iOS app成为可能的驱动力. Xcode能帮助我们完成非常多的事情,但是这也有点让人头 ...
- AJ学IOS(02)UI之按钮操作 点击变换 移动 放大缩小 旋转
不多说,先上图片看效果,AJ分享,必须精品 这个小程序主要实现点击方向键可以让图标上下左右动还有放大缩小以及旋转的功能,点击图片会显示另一张图片. 点击变换 其实用到了按钮的两个状态,再State C ...
- python脚本如何同时运行多个
当我们想一次运行多个py脚本的时候你想到了什么应用场景了吗?当你想同时并行的处理一些对象时你有什么好方法吗?下面我就简单的总结一些这方面的小技巧,方便大家根据情况灵活处理. 1 用一个py脚本运行多个 ...
- atom跨平台超好用的markdown实时预览
https://atom.io/ sublime有预览markdown的插件,但仅限于每次在浏览器中预览,想要找一个能够实时在软件中预览的,终于发现了atom. 很多功能以插件的形式安装,theme也 ...
- C#开发BIMFACE系列31 服务端API之模型对比2:获取模型对比状态
系列目录 [已更新最新开发文章,点击查看详细] 在上一篇<C#开发BIMFACE系列30 服务端API之模型对比1:发起模型对比>中发起了2个模型对比,由于模型对比是在BIMFAC ...
- PHP 常用数组的具体运用?常用吗?
在 PHP 中,有三种类型的数组: 数值数组 - 带有数字 ID 键的数组 关联数组 - 带有指定的键的数组,每个键关联一个值 多维数组 - 包含一个或多个数组的数组 看具体实例: 创建数组 < ...
- MySQL笔记总结-DDL语言
DDL语言 数据类型 一.数值型 1.整型 tinyint.smallint.mediumint.int/integer.bigint 1 2 3 4 8 特点: ①都可以设置无符号和有符号,默认有符 ...
- 使用dynamic和MEF实现轻量级的AOP组件 (3)
转摘 https://www.cnblogs.com/niceWk/archive/2010/07/22/1783068.html 水到渠成 在上一篇的<偷梁换柱>中,介绍了Weavabl ...