题目

由\(1,2,\dots,n-1,n\)组成的序列中有多少个子序列是等比数列\((n\leq 5*10^{17})\)


分析

分类讨论,先设公比为\(q=\frac{i}{j}[gcd(i,j)==1,i>j]\)

首先长度为1或2的有\(\frac{n(n+1)}{2}\)个

考虑长度大于3的可以暴力处理,枚举长度和分子\(i\)

公比不同的等比数列有\(\varphi(i)\)个,首项一共有\(\lfloor\frac{n}{i^{len-1}}\rfloor\)中情况

那么

\[ans=\sum_{i=2}^n\sum_{len=4}\varphi(i)\lfloor\frac{n}{i^{len-1}}\rfloor
\]

长度等于3同理可得

\[ans=\sum_{i=2}^n\varphi(i)\lfloor\frac{n}{i^2}\rfloor
\]

整除分块+杜教筛,就不会TLE了

怎么用杜教筛??套模板就可以了


代码

#include <cstdio>
#include <cctype>
#include <cmath>
#include <map>
#define rr register
using namespace std;
const int N=40000011,mod=998244353;
int phi[N],prime[N],Cnt; bool v[N];
typedef long long lll; map<int,int>uk;
inline signed mo(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline signed od(int x,int y){return x<y?x+mod-y:x-y;}
inline void Pro(int n){
phi[1]=1;
for (rr int i=2;i<=n;++i){
if (!v[i]) prime[++Cnt]=i,phi[i]=i-1;
for (rr int j=1;j<=Cnt&&prime[j]<=n/i;++j){
v[i*prime[j]]=1,phi[i*prime[j]]=phi[i]*(prime[j]-1);
if (i%prime[j]==0) {
phi[i*prime[j]]+=phi[i];
break;
}
}
}
for (rr int i=2;i<=n;++i) phi[i]=mo(phi[i-1],phi[i]);
}
inline signed sphi(int n){
if (n<=N-11) return phi[n];
if (uk.find(n)!=uk.end()) return uk[n];
rr int ans=(1ll*n*(n+1)>>1)%mod;
for (rr int l=2,r;l<=n;l=r+1)
r=n/(n/l),ans=od(ans,1ll*sphi(n/l)*(r-l+1)%mod);
return ans;
}
signed main(){
Pro(N-11); rr int Test;
for (scanf("%d",&Test);Test;--Test){
rr lll n,t; scanf("%lld",&n);
rr int ans=((n%mod)*((n%mod)+1)>>1)%mod;
rr int t1=sqrt(n),t2=pow(n,1.0/3);
for (rr int l=2,r,w;l<=t1;l=r+1)
t=n/l/l,r=sqrt(n/t),ans=mo(ans,t*od(sphi(r),sphi(l-1))%mod);
for (rr int i=2;i<=t2;++i)
for (rr lll t=1ll*i*i*i;;t*=i){
ans=mo(ans,(n/t)*od(phi[i],phi[i-1])%mod);
if (t>n/i) break;
}
printf("%d\n",ans);
}
return 0;
}

#杜教筛,欧拉函数,整除分块#HDU 6683 Rikka with Geometric Sequen的更多相关文章

  1. 51Nod.1237.最大公约数之和 V3(莫比乌斯反演 杜教筛 欧拉函数)

    题目链接 \(Description\) \(n\leq 10^{10}\),求 \[\sum_{i=1}^n\sum_{j=1}^ngcd(i,j)\ mod\ (1e9+7)\] \(Soluti ...

  2. luogu P3768 简单的数学题 杜教筛 + 欧拉反演 + 逆元

    求 $\sum_{i=1}^{n}\sum_{j=1}^{n}ijgcd(i,j)$   考虑欧拉反演: $\sum_{d|n}\varphi(d)=n$   $\Rightarrow \sum_{i ...

  3. 2019年南京网络赛E题K Sum(莫比乌斯反演+杜教筛+欧拉降幂)

    目录 题目链接 思路 代码 题目链接 传送门 思路 首先我们将原式化简: \[ \begin{aligned} &\sum\limits_{l_1=1}^{n}\sum\limits_{l_2 ...

  4. The Euler function(线性筛欧拉函数)

    /* 题意:(n)表示小于n与n互质的数有多少个,给你两个数a,b让你计算a+(a+1)+(a+2)+......+b; 初步思路:暴力搞一下,打表 #放弃:打了十几分钟没打完 #改进:欧拉函数:具体 ...

  5. 素数的线性筛 && 欧拉函数

    O(n) 筛选素数 #include<bits/stdc++.h> using namespace std; const int M = 1e6 + 10 ; int mindiv[M] ...

  6. HDU5780 gcd (BestCoder Round #85 E) 欧拉函数预处理——分块优化

    分析(官方题解): 一点感想: 首先上面那个等式成立,然后就是求枚举gcd算贡献就好了,枚举gcd当时赛场上写了一发O(nlogn)的反演,写完过了样例,想交发现结束了 吐槽自己手速慢,但是发了题解后 ...

  7. BZOJ 2818 GCD 素数筛+欧拉函数+前缀和

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=n且Gcd(x,y)为素数的数对( ...

  8. [bzoj 2190][SDOI2008]仪仗队(线性筛欧拉函数)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2190 分析:就是要线性筛出欧拉函数... 直接贴代码了: memset(ans,,sizeof ...

  9. 积性函数&线性筛&欧拉函数&莫比乌斯函数&因数个数&约数个数和

    只会搬运YL巨巨的博客 积性函数 定义 积性函数:对于任意互质的整数a和b有性质f(ab)=f(a)f(b)的数论函数. 完全积性函数:对于任意整数a和b有性质f(ab)=f(a)f(b)的数论函数 ...

  10. Farey Sequence (素筛欧拉函数/水)题解

    The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...

随机推荐

  1. [Android逆向]Exposed 破解 jwxdxnx02.apk

    使用exposed 遇到了一些坑,这里记录一下 源码: package com.example.exposedlesson01; import de.robv.android.xposed.IXpos ...

  2. instance must be started before calling this method

    解决方法 检查zk的连接数: 端口号: 数据库连接配置: zk的连接配置: 如果都没有问题,就重启容器.

  3. Javascript之Object、Array

    Object.keys 对象的键转化为数组 Object.values 对象的属性值转化为数组 Object.assign 对象的合并   Array.from() 伪数组对象的属性值转化为数组.类似 ...

  4. 【Azure 环境】AAD 注册应用获取AAD Group权限接口遇 403 : Attempted to perform an unauthorized operation 错误

    问题描述 通过Azure AD的注册应用获取到Token后,访问AAD Group并查看日志信息时候,遇见了 {"error":{"code":"Un ...

  5. 【Azure Redis 缓存】使用StackExchange.Redis,偶发ERROR - Timeout performing HSET (15000ms)

    问题描述 使用StackExchange.Redis 作为Redis客户端SDK,连接Azure Redis服务,长期运行后发现,每天都偶发 Timeout Error. 错误消息如下: StackE ...

  6. 【Azure 环境】在Azure活动目录中的应用注册,给应用添加API权限时发现API权限配置缺失

    问题描述 在Azure活动目录中的应用注册,给应用添加API权限时,SecurityEvents.Read.All和IdentityRiskEvent两个权限,在Microsoft graph中找不到 ...

  7. 【Azure 环境】台湾同胞:詢問大陸所有廠牌手機是否都可透過通知中心發送訊息

    什么是 Azure 通知中心? Azure 通知中心提供易于使用且向外扩展的推送引擎,可用于将通知发送到任何平台 (iOS.Android.Windows.Kindle.百度等 ) 从任何后端 (云和 ...

  8. 百度爱番番基于图技术、流式计算的实时CDP建设实践

    导读:随着营销3.0时代的到来,企业愈发需要依托强大CDP能力解决其严重的数据孤岛问题,帮助企业加温线索.促活客户.但什么是CDP.好的CDP应该具备哪些关键特征?本文在回答此问题的同时,详细讲述了爱 ...

  9. Ubuntu中安装使用QEMU/KVM/virt-manager运行虚拟机

    本文为原创,原文发布于个人博客网站:Ubuntu中安装使用QEMU/KVM/virt-manager运行虚拟机 有时候我们需要在同一台计算机中使用多种不同操作系统环境,基于已有的同一堆硬件资源来获得不 ...

  10. Kotlin扩展函数与属性原理解析

    一.扩展函数 扩展函数可以方便地给现有类增加属性和方法而不改动类地代码. 二.原理 fun String.addTo(s: String): String{ return this + s } 反编译 ...