题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5382

题意:函数lcm(a,b):求两整数a,b的最小公倍数;函数gcd(a,b):求两整数a,b的最大公约数。函数[exp],其中exp是一个逻辑表达式。如果逻辑表达式exp是真,那么函数[exp]的值是1,否则函数[exp]的值是0。例如:[1+2>=3] = 1 ,[1+2>=4] = 0。

求S(n)的值。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int mod = 258280327;
bool isprime[maxn];
LL prime[maxn], primecnt, num[maxn];
LL G[maxn], T[maxn], F[maxn], S[maxn];
LL qsm(LL a, LL n){
LL ret = 1;
while(n){
if(n&1) ret = ret*a%mod;
a=a*a%mod;
n>>=1;
}
return ret;
}
void pre_deal(){
memset(isprime, true, sizeof(isprime));
memset(num, 0, sizeof(num));
for(int i=2; i<maxn; i++){
if(isprime[i]){
num[i]++;
for(int j=i+i; j<maxn; j+=i){
isprime[j] = false;
num[j]++;
}
}
}
for(int i=2; i<maxn; i++){
if(isprime[i]){
prime[primecnt++]=i;
}
}
}
void INIT()
{
pre_deal();
G[0] = 0;
for(int i=1; i<maxn; i++){
G[i] = qsm(2, num[i]);
}
memset(T, 0, sizeof(T));
memset(F, 0, sizeof(F));
memset(S, 0, sizeof(S));
for(int i=1; i<maxn; i++){
for(int j=i; j<maxn; j+=i){
T[j]=(T[j]+G[j/i-1])%mod;
}
}
F[1] = S[1] = 1;
for(int i=2; i<maxn; i++){
F[i] = ((F[i-1]+2*i-1+mod)%mod-(T[i-1]%mod)+mod)%mod;
S[i] = (S[i-1] + F[i])%mod;
}
}
int main()
{
INIT();
LL n;
int T;
scanf("%d", &T);
while(T--)
{
scanf("%lld", &n);
printf("%lld\n", S[n]);
}
return 0;
}

2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导的更多相关文章

  1. 2015多校第6场 HDU 5354 Bipartite Graph CDQ,并查集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5354 题意:求删去每个点后图是否存在奇环(n,m<=1e5) 解法:很经典的套路,和这题一样:h ...

  2. 2015多校第6场 HDU 5361 并查集,最短路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5361 题意:有n个点1-n, 每个点到相邻点的距离是1,然后每个点可以通过花费c[i]的钱从i点走到距 ...

  3. 2015多校第6场 HDU 5355 Cake 贪心,暴力DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 题意:给你n个尺寸大小分别为1,2,3,…,n的蛋糕,要求你分成m份,要求每份中所有蛋糕的大小之 ...

  4. 2015多校第6场 HDU 5358 First One 枚举,双指针

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358 题意:如题. 解法:观察式子发现,由于log函数的存在,使得这个函数的值域<=34,然后我 ...

  5. 2015多校第6场 HDU 5360 Hiking 贪心,优先队列

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...

  6. 2015多校第6场 HDU 5353 Average 贪心,细节处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5353 题意:有n个人围城一个环,每一个人手里都有一些糖果,第i个人有ai块.现在有三种操作:第i个人给 ...

  7. 2015多校第9场 HDU 5405 Sometimes Naive 树链剖分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5405 题意: 给你一棵n个节点的树,有点权.        要求支持两种操作: 操作1:更改某个节点的 ...

  8. 2015多校第7场 HDU 5378 Leader in Tree Land 概率DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5378 题意:一棵n个节点的树.对其节点进行标号(1~n).求恰好存在k个节点的标号是其节点所在子树的最 ...

  9. 2015多校第7场 HDU 5379 Mahjong tree 构造,DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5379 题意:一颗n个节点n-1条边的树,现在要给每个节点标号(1~n),要求:(1)每一层的兄弟节点的 ...

随机推荐

  1. BZOJ4289 PA2012Tax(最短路)

    一个暴力的做法是把边看成点,之间的边权为两边的较大权值,最短路即可.但这样显然会被菊花图之类的卡掉. 考虑优化建图.将边拆成两个有向边,同样化边为点.原图中同一条边在新图中的两个点之间连边权为原边权的 ...

  2. [CF1095F]Make It Connected

    题目大意:给你$n(n\leqslant2\times10^5)$个点和$m(m\leqslant2\times10^5)$条边,第$i$个点点权为$a_i$.连接$u,v$两个点的代价为$a_u+a ...

  3. Android <Android应用开发实战> 资源类型<一>

    1.字符串资源>>1.普通字符串>>2.字符串数组 <resources> <string-array name="planets_array&qu ...

  4. POJ1375:Intervals——题解

    http://poj.org/problem?id=1375 题目大意:有一盏灯,求每段被圆的投影所覆盖的区间. —————————————————————— 神题,卡精度,尝试用各种方法绕过精度都不 ...

  5. BZOJ1854:[SCOI2010]连续攻击游戏——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1854 https://www.luogu.org/problemnew/show/P1640 lxh ...

  6. POJ1201:Intervals(差分约束)

    差分约束经典题.设s[i]为前缀和,则有 s[i]-s[i-1]<=1 (i往i-1连-1的边) s[i]>=s[i-1] (i-1往i连0的边) s[b]-s[a-1]>=c (a ...

  7. hdoj 1299 Diophantus of Alexandria

    hdoj 1299 Diophantus of Alexandria 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题意:求 1/x + 1/y ...

  8. (转)史上最好的Python线程指南

    来自AstalWind的好文,彻底认识python线程 http://www.cnblogs.com/huxi/archive/2010/06/26/1765808.html . . . . .

  9. 替换Jar包中的一个文件 Replace a file in a JAR

    例如: jar uf myJarFile.jar com\vsoft\servlet\myServlet.class This will replace the class myServlet.cla ...

  10. 插入排序Insertion sort 2

    原理类似桶排序,这里总是需要10个桶,多次使用 首先以个位数的值进行装桶,即个位数为1则放入1号桶,为9则放入9号桶,暂时忽视十位数 例如 待排序数组[62,14,59,88,16]简单点五个数字 分 ...