题目大意

定义函数\(f(x)=\sum_{k|x}k\)

\(t\)(\(t\leq2*10^4\))组询问,每组给定\(n,m,a\)(\(n,m\leq10^5,a\leq10^9\)),求:

\[\sum_{i=1}^{n}\sum_{j=1}^{m}[f(gcd(i,j))\leq a]f(gcd(i,j))\space mod 2^{31}
\]

题解

这个人(点这里)讲得很清楚\(\color{white}{\text{shing太强了}}\)

除此之外,因为模数是2的整数次幂,所以需要模的时候可以直接按位与\(2^{31}-1\)

代码
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define rep(i,x,y) for(register int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(register int i=(x);i>=(y);--i)
#define maxn 100010
#define lim (maxn-10)
#define LL long long
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
void write(LL x)
{
if(x==0){putchar('0'),putchar('\n');return;}
int f=0;char ch[20];
if(x<0)putchar('-'),x=-x;
while(x)ch[++f]=x%10+'0',x/=10;
while(f)putchar(ch[f--]);
putchar('\n');
return;
}
const LL mod=(1ll<<31)-1;
int t,no[maxn],p[maxn],cnt;
struct quest{int n,m,a,id;LL ans;}q[20010];
struct funct{int x;LL f;}fu[maxn];
LL mu[maxn],g[maxn];
int lt(int x){return x&(-x);}
void add(int x,LL k){for(;x<=lim;x+=lt(x))g[x]=(g[x]+k)&mod;}
LL ask(int x){LL k=0;for(;x;x-=lt(x))k=(k+g[x])&mod;return k;}
bool cmpa(quest x,quest y){return x.a<y.a;}
bool cmpf(funct x,funct y){return x.f<y.f;}
bool cmpid(quest x,quest y){return x.id<y.id;}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
no[1]=mu[1]=1;
rep(i,2,lim)
{
if(!no[i])p[++cnt]=i,mu[i]=-1;
for(int j=1;j<=cnt&&i*p[j]<=lim;j++)
{
no[i*p[j]]=1;
if(i%p[j]==0){mu[i*p[j]]=0;break;}
mu[i*p[j]]=-mu[i];
}
}
rep(i,1,lim)
{
fu[i].x=i;
for(int j=i;j<=lim;j+=i)fu[j].f=(fu[j].f+i)&mod;
}
sort(fu+1,fu+lim+1,cmpf);
t=read();
rep(i,1,t)
{
q[i].n=read(),q[i].m=read(),q[i].a=read(),q[i].id=i;
if(q[i].n>q[i].m)swap(q[i].n,q[i].m);
}
sort(q+1,q+t+1,cmpa);int now=0;
rep(i,1,t)
{
while(now+1<=lim&&fu[now+1].f<=q[i].a)
{
now++;
for(int j=fu[now].x;j<=lim;j+=fu[now].x)add(j,(mu[j/fu[now].x]*fu[now].f)&mod);
}
for(int l=1,r=0;l<=q[i].n;l=r+1)
{
r=min(q[i].n/(q[i].n/l),q[i].m/(q[i].m/l));
q[i].ans=(q[i].ans+((((LL)(q[i].n/l)*(LL)(q[i].m/l))&mod)*((ask(r)-ask(l-1)+mod+1ll)&mod))&mod)&mod;
}
}
sort(q+1,q+t+1,cmpid);
rep(i,1,t)write(q[i].ans);
return 0;
}

并不对劲的bzoj3529:loj2193:p3312:[SDOI2014]数表的更多相关文章

  1. 洛谷 P3312 [SDOI2014]数表 解题报告

    P3312 [SDOI2014]数表 题目描述 有一张\(N*M\)的数表,其第\(i\)行第\(j\)列(\(1\le i \le n\),\(1 \le j \le m\))的数值为能同时整除\( ...

  2. 洛谷P3312 - [SDOI2014]数表

    Portal Solution 共\(T(T\leq2\times10^4)\)组测试数据.给出\(n,m(n,m\leq10^5),a(a\leq10^9)\),求\[ \sum_{i=1}^n\s ...

  3. [bzoj3529] [洛谷P3312] [Sdoi2014] 数表

    Description 有一张n×m的数表,其第i行第j列(1 < =i < =n,1 < =j < =m)的数值为 能同时整除i和j的所有自然数之和.给定a,计算数表中不大于 ...

  4. P3312 [SDOI2014]数表

    啊啊啊我昨天怎么没写题解wwww 补昨日题解... 题目链接 : https://www.luogu.org/problemnew/show/P3312 也是莫反 我要把fft留到今天写 [和zyn小 ...

  5. luogu P3312 [SDOI2014]数表

    传送门 我们看要求的东西\[\sum_{i=1}^{n}\sum_{j=1}^{m}[\sigma(gcd(i,j))\le a]\sigma(gcd(i,j))\] 然而\(\le a\)比较烦,可 ...

  6. 洛谷P3312 [SDOI2014]数表(莫比乌斯反演+树状数组)

    传送门 不考虑$a$的影响 设$f(i)$为$i$的约数和 $$ans=\sum\limits_{i=1}^n\sum\limits_{j=1}^nf(gcd(i,j))$$ $$=\sum\limi ...

  7. 洛谷 P3312 [SDOI2014]数表

    式子化出来是$\sum_{T=1}^m{\lfloor}\frac{n}{T}{\rfloor}{\lfloor}\frac{m}{T}{\rfloor}\sum_{k|T}\mu(\frac{T}{ ...

  8. 【BZOJ3529】[Sdoi2014]数表 莫比乌斯反演+树状数组

    [BZOJ3529][Sdoi2014]数表 Description 有一张N×m的数表,其第i行第j列(1 < =i < =礼,1 < =j < =m)的数值为能同时整除i和 ...

  9. BZOJ3529 [Sdoi2014]数表 【莫比乌斯反演】

    3529: [Sdoi2014]数表 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2151 Solved: 1080 [Submit][Status ...

随机推荐

  1. python013 Python3 循环语句

    Python3 循环语句本章节将为大家介绍Python循环语句的使用.Python中的循环语句有 for 和 while.Python循环语句的控制结构图如下所示: while 循环Python中wh ...

  2. 使用cURL和用户名和密码?

    问题描述 我想访问一个需要用户名/密码的URL.我想尝试用 curl 来访问它.现在我正在做一些事情: curl http://api.somesite.com/test/blah?something ...

  3. 动手实操:如何用 Python 实现人脸识别,证明这个杨幂是那个杨幂?

    当前,人脸识别应用于许多领域,如支付宝的用户认证,许多的能识别人心情的 AI,也就是人的面部表情,还有能分析人的年龄等等,而这里面有着许多的难度,在这里我想要分享的是一个利用七牛 SDK 简单的实现人 ...

  4. POJ 1985 Cow Marathon【树的直径】

    题目大意:给你一棵树,要你求树的直径的长度 思路:随便找个点bfs出最长的点,那个点一定是一条直径的起点,再从那个点BFS出最长点即可 以下研究了半天才敢交,1.这题的输入格式遵照poj1984,其实 ...

  5. Hankson 的趣味题(codevs 1172)

    题目描述 Description Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson 正在思考一个有趣的问题.今天在 ...

  6. 【译】Nodejs最好的ORM

    TypeORM github: https://github.com/typeorm/typeorm这篇译文是从TypeORM github上的使用说明上翻译过来的,已经提交PR并merge到库中了. ...

  7. Http、TCP/IP、Socket的区别

    网络由下往上分为 物理层.数据链路层.网络层.传输层.会话层.表示层和应用层. 通过初步的了解,我知道IP协议对应于网络层,TCP协议对应于传输层,而HTTP协议对应于应用层, 三者从本质上来说没有可 ...

  8. 远程连接mongodb时,27017端口连接不上的解决办法

    一.背景描述: 我在linux  RED7上安装了mongodb,并没有修改mongodb的配置文件.然后通过另外一台电脑用pymongo连接mongodb时,报错:timeout. ping IP ...

  9. msp430项目编程21

    msp430中项目---直流电机控制系统 1.定时器工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习

  10. PAT (Advanced Level) 1036. Boys vs Girls (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...