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的最大公约数。函数[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! 数论公式推导的更多相关文章
- 2015多校第6场 HDU 5354 Bipartite Graph CDQ,并查集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5354 题意:求删去每个点后图是否存在奇环(n,m<=1e5) 解法:很经典的套路,和这题一样:h ...
- 2015多校第6场 HDU 5361 并查集,最短路
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5361 题意:有n个点1-n, 每个点到相邻点的距离是1,然后每个点可以通过花费c[i]的钱从i点走到距 ...
- 2015多校第6场 HDU 5355 Cake 贪心,暴力DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 题意:给你n个尺寸大小分别为1,2,3,…,n的蛋糕,要求你分成m份,要求每份中所有蛋糕的大小之 ...
- 2015多校第6场 HDU 5358 First One 枚举,双指针
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358 题意:如题. 解法:观察式子发现,由于log函数的存在,使得这个函数的值域<=34,然后我 ...
- 2015多校第6场 HDU 5360 Hiking 贪心,优先队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5360 题意:给定n个人,现在要邀请这些人去远足,但每个人同意邀请的条件是当前已经同意去远足的人数c必须 ...
- 2015多校第6场 HDU 5353 Average 贪心,细节处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5353 题意:有n个人围城一个环,每一个人手里都有一些糖果,第i个人有ai块.现在有三种操作:第i个人给 ...
- 2015多校第9场 HDU 5405 Sometimes Naive 树链剖分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5405 题意: 给你一棵n个节点的树,有点权. 要求支持两种操作: 操作1:更改某个节点的 ...
- 2015多校第7场 HDU 5378 Leader in Tree Land 概率DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5378 题意:一棵n个节点的树.对其节点进行标号(1~n).求恰好存在k个节点的标号是其节点所在子树的最 ...
- 2015多校第7场 HDU 5379 Mahjong tree 构造,DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5379 题意:一颗n个节点n-1条边的树,现在要给每个节点标号(1~n),要求:(1)每一层的兄弟节点的 ...
随机推荐
- BZOJ1861:[ZJOI2006]书架——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1861 (题面复制于洛谷) 题目描述 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上 ...
- 51nod 1554:欧姆诺姆和项链——题解
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1554 题目: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色 ...
- [Leetcode] valid parentheses 有效括号对
Given a string containing just the characters'(',')','{','}','['and']', determine if the input strin ...
- eclipse中支持python
1. 启动eclipse,help-> Install New Software; 2. 点击add 3. 设置Repository name: pydev Location: http://p ...
- Codeforces Round #340 (Div. 2)B
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- mysql concat update中拼接字符串
mysql> select id,avatar from tf_user; +----+--------------+ | id | avatar | +----+--------------+ ...
- template.js的使用心得
template.js是一款JavaScript模板引擎,用来渲染页面的. 原理:提前将Html代码放进编写模板 <script id="tpl" type="te ...
- spoj COT2 - Count on a tree II
COT2 - Count on a tree II http://www.spoj.com/problems/COT2/ #tree You are given a tree with N nodes ...
- 51nod 1170 1770 数数字(数学技巧)
解题思路:看到题后,直接想到分成两种情况: ①:a*b >9 这里又分成两种 1. n==1 a*b 直接是一个两位数 求得十位和个位(这里十位和个位不可能相等) 然后如果等于d 则结果=1 2 ...
- Response.Redirect在新窗口打开(转载)
Response.Rederect在默认情况下是在本页跳转,所以除了在js中用window.open或是给A标签添加target属性之外,在后台似乎不能来打开新的页面,其实不然,通过设置form的ta ...