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?(详细推导,不懂打我)的更多相关文章

  1. 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的最 ...

  2. hdu 5382 GCD?LCM! - 莫比乌斯反演

    题目传送门 传送门I 传送门II 题目大意 设$F(n) = \sum_{i = 1}^{n}\sum_{j = 1}^{n}\left [ [i, j] + (i, j) \geqslant n \ ...

  3. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  4. 数学--数论--HDU 5223 - GCD

    Describtion In mathematics, the greatest common divisor (gcd) of two or more integers, when at least ...

  5. hdu 5382 GCD?LCM!

    先考虑化简f函数 发现,f函数可以写成一个递归式,化简后可以先递推求出所有f函数的值, 所以可以先求出所有S函数的值,对于询问,O(1)回答 代码: //File Name: hdu5382.cpp ...

  6. 数论入门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 ...

  7. 数学--数论--HDU 5019 revenge of GCD

    Revenge of GCD Problem Description In mathematics, the greatest common divisor (gcd), also known as ...

  8. 数学--数论--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 ...

  9. 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) ...

随机推荐

  1. JAVA中Calendar 类的应用

    转自:https://www.imooc.com/code/2340 侵删! Date 类最主要的作用就是获得当前时间,同时这个类里面也具有设置时间以及一些其他的功能,但是由于本身设计的问题,这些方法 ...

  2. js骚操作骂人不带脏

    前言 很多小伙伴们觉得javaScript很简单,下面的这行 javaScript代码可能会让你怀疑人生. (!(~+[])+{})[--[~+""][+[]]*[~+[]] + ...

  3. Kitty-Cloud服务搭建过程剖析

    项目地址 https://github.com/yinjihuan/kitty-cloud 服务搭建 大家目前看到的都是我已经搭建好了的服务,如果让你从零开始自己搭建一个微服务的项目,要怎么做? 我们 ...

  4. redis 正确实现分布式锁的正确方式

    前言 最近在自己所管理的项目中,发现redis加锁的方式不对,在高并发的情况有问题.故在网上找搜索了一把相关资料.发现好多都是互相抄袭的,很多都是有缺陷的.好多还在用redis 的 setnx命令来实 ...

  5. editplus 怎么替换为换行

    到editplus 的搜索 菜单中,选择替换,记住 这边如果是简单的一些 通用字符 替换可以直接替换,如果是一些特殊的字符 那必须选择 替换框左下中间的 “正则表达式”,即把这个“正则表达式” 前边的 ...

  6. 关于在React中 报Super expression must either be null or a function, not undefined (采坑系列)

    今天突然在联系React中遇到一开始就报    Super expression must either be null or a function, not undefined 百度,各种方法,.. ...

  7. syncronized如何上锁

    上锁,根据操作系统所说的原则,对共享变量上锁,对临界区上锁.谁访问临界资源?就给谁上锁 同步监视器,它上锁的对象. 1.用关键字给方法上锁 2.用synchronized代码块上锁 默认上锁对象:th ...

  8. sqli-labs通关----11~20关

    第十一关 从第十一关开始,就开始用post来提交数据了,我们每关的目的都是获取users表下password字段的内容. post是一种数据提交方式,它主要是指数据从客户端提交到服务器端,例如,我们常 ...

  9. 掉了10根头发都无法解决的数学题,python帮你完美解答

    本来这个周末过得开开心心,结果为了解一道数学题薅掉了一把头发...整整10根! 而且还是一道小学数学题!!! 到底是什么题呢?大家看看吧 这不就是一道逻辑题嘛! 先假如丁错,则甲乙丙对,此时最小的ab ...

  10. stand up meeting 12/8/2015

    part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云  --------------    --  -----------  -- PDF Reader 朱玉影         ...