数学--数论--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) ...
随机推荐
- 关于Linux目录的配置
关于Linux目录的配置说明 大家都知道Linux一切皆文件,但是Linux的文件有那么多,目录也不少.他们都是干什么用的呢,有没有什么规律呢?今天我们就来讨论一下Linux目录的配置 Linux目录 ...
- SQL表的简单操作
创建数据库表,进行增删改查是我们操作数据库的最基础的操作,很简单,熟悉的请关闭,免得让费时间. 1.创建表: sql中创建数值类型字段要根据该字段值的增长情况选择类型: tinyint 占1个字节,长 ...
- 第一天总结(while计数器+成绩大小+获取时间+猜拳大小)
#*_* coding:utf-8 *_*# while 先有一个计数器 input = 0# input = input('输入数字')while input < 5: input= inpu ...
- 理解class.forName() ---使用jdbc方式链接数据库时会经常看到这句代码
目录(?)[-] 官方文档 类装载 两种装载方法的区别 不同的类装载器 是否实例化类 在jdbc链接数据库中的应用 资源 原文地址:http://yanwushu.sinaapp.com/clas ...
- getline()和get()的使用区别
一.getline和get()的使用区别: 首先这两个函数都读取下一行输入,直到到达换行符:但是getline()函数会丢弃换行符,而get()将换行符保留在输入序列中 二.getline()函数的使 ...
- Three.js如何选中外部模型
1.问题 three.js中模型选中使用的是射线法,根据摄像机角度,鼠标点击位置和模型选中的distance参数判断来选中模型.对于原生的矢量模型完全没有问题,但是当遇到导入的外部模型,如obj.st ...
- 关于 System.IO.File.Exists 需要注意的事项
各位: .NET Framework 本省在设计的时候,他对于异常没有完全做到抛出,这样可能会有很多意想不到的问题. 比如 你在asp.net 应用程序中判断文件是否存在,这个文件可能是一个共 ...
- python干货:5种反扒机制的解决方法
前言 反爬虫是网站为了维护自己的核心安全而采取的抑制爬虫的手段,反爬虫的手段有很多种,一般情况下除了百度等网站,反扒机制会常常更新以外.为了保持网站运行的高效,网站采取的反扒机制并不是太多,今天分享几 ...
- Linux 平台 安装 Composer
1.检查是否安装 composer --version 2.下载安装 php -r "copy('https://install.phpcomposer.com/installer', 'c ...
- 详解 ServerSocket与Socket类
(请观看本人博文 -- <详解 网络编程>) 目录 ServerSocket与Socket ServerSocket 类: Socket类: ServerSocket与Socket 首先, ...