2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导
2024-09-18 02:28:15
题目链接: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;
}
最新文章
- java 文件上传
- JQuery遍历方法$.each输出函数
- ecshop 默认图处理
- IE6对png图片的处理
- h5上滑刷新(分页)
- MapReduce实现TopK的示例
- 找不到请求的 .Net Framework Data Provider。可能没有安装.
- iOS8 蓝牙设备的重连接(retrieve) Swift实现
- python中并行遍历:zip和map-转
- [RxJS] Filtering operators: throttle and throttleTime
- NOI 191钉子和小球.cpp
- stm32之GPIO
- [.NET] 《Effective C#》快速笔记 - C# 中的动态编程
- phpcms v9 sql注入脚本
- ConditionalOnBean 与 ConditionalOnMissingBean 的正确玩法
- 使用ElasticSearch服务从MySQL同步数据实现搜索即时提示与全文搜索功能
- shell 查询oracle数据库
- Vue的路由设置
- c# 4.0 - how to i SMTP with c# 4/.NET 4 to port 465/SSL (...
- Photoshop图层混合模式计算公式大全