题目链接: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;
}

最新文章

  1. java 文件上传
  2. JQuery遍历方法$.each输出函数
  3. ecshop 默认图处理
  4. IE6对png图片的处理
  5. h5上滑刷新(分页)
  6. MapReduce实现TopK的示例
  7. 找不到请求的 .Net Framework Data Provider。可能没有安装.
  8. iOS8 蓝牙设备的重连接(retrieve) Swift实现
  9. python中并行遍历:zip和map-转
  10. [RxJS] Filtering operators: throttle and throttleTime
  11. NOI 191钉子和小球.cpp
  12. stm32之GPIO
  13. [.NET] 《Effective C#》快速笔记 - C# 中的动态编程
  14. phpcms v9 sql注入脚本
  15. ConditionalOnBean 与 ConditionalOnMissingBean 的正确玩法
  16. 使用ElasticSearch服务从MySQL同步数据实现搜索即时提示与全文搜索功能
  17. shell 查询oracle数据库
  18. Vue的路由设置
  19. c# 4.0 - how to i SMTP with c# 4/.NET 4 to port 465/SSL (...
  20. Photoshop图层混合模式计算公式大全

热门文章

  1. Javascript基础之-强制类型转换(二)
  2. POJ2286:The Rotation Game——题解
  3. BZOJ2458:[BJOI2011]最小三角形——题解
  4. POJ 2774 求两个串的最长公共前缀 | 后缀数组
  5. php 获取客户端IP地址经纬度所在城市
  6. 【简单算法】22.删除链表的倒数第N个节点
  7. mybatis 根据id批量删除的两种方法
  8. linux 下文件重命名/移动/复制命令(转)
  9. rm删除破折号 - 开头的文件
  10. jquery禁用按钮