DZY Loves Math

Time Limit: 20 Sec  Memory Limit: 512 MB
Submit: 1303  Solved: 819
[Submit][Status][Discuss]

Description

对于正整数n,定义f(n)为n所含质因子的最大幂指数。例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0。
给定正整数a,b,求sigma(sigma(f(gcd(i,j)))) (i=1..a, j=1..b)。

Input

第一行一个数T,表示询问数。
接下来T行,每行两个数a,b,表示一个询问。

Output

对于每一个询问,输出一行一个非负整数作为回答。

Sample Input

4
7558588 9653114
6514903 4451211
7425644 1189442
6335198 4957

Sample Output

35793453939901
14225956593420
4332838845846
15400094813

HINT

【数据规模】

T<=10000

 #pragma GCC optimize(2)
#pragma G++ optimzie(2)
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream> #define N 10000007
#define ll long long
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,m;
int pri[N],tot;
int t[N],last[N],g[N];
bool flag[N]; void init()
{
for (int i=;i<N;i++)
{
if(!flag[i])
{
pri[++tot]=i;
last[i]=t[i]=g[i]=;
}
for(int j=;pri[j]*i<N&&j<=tot;j++)
{
int x=i*pri[j];flag[x]=true;
if(i%pri[j]==)
{
last[x]=last[i];
t[x]=t[i]+;
if(last[x]==)g[x]=;
else g[x]=(t[last[x]]==t[x]?-g[last[x]]:);
break;
}
else
{
last[x]=i;
t[x]=;
g[x]=(t[i]==?-g[i]:);
}
}
}
for (int i=;i<N;i++)g[i]+=g[i-];
/* for (int i=11;i<=20;i++)
cout<<"xzpxzpxzpxzpxzpxzp==laji="<<g[i]<<endl;*/
}
ll solve(int n,int m)
{
if(n>m)swap(n,m);ll res=;
for (int i=,last;i<=n;i=last+)
{
last=min(n/(n/i),m/(m/i));
res+=1ll*(n/i)*(m/i)*(g[last]-g[i-]);
}
return res;
}
int main()
{
init();
int T=read();
while(T--)
{
n=read(),m=read();
printf("%lld\n",solve(n,m));
}
}

bzoj 3309 DZY Loves Math 莫比乌斯反演的更多相关文章

  1. BZOJ 3309 DZY Loves Math ——莫比乌斯反演

    枚举$d=gcd(i,j)$ 然后大力反演 ——来自Popoqqq的博客. 然后大力讨论后面的函数的意义即可. http://blog.csdn.net/popoqqq/article/details ...

  2. bzoj 3309 DZY Loves Math —— 莫比乌斯反演+数论分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 凭着上课所讲和与 Narh 讨论推出式子来: 竟然是第一次写数论分块!所以迷惑了半天: ...

  3. BZOJ 3309: DZY Loves Math [莫比乌斯反演 线性筛]

    题意:\(f(n)\)为n的质因子分解中的最大幂指数,求\(\sum_{i=1}^n \sum_{j=1}^m f(gcd(i,j))\) 套路推♂倒 \[ \sum_{D=1}^n \sum_{d| ...

  4. BZOJ 3309: DZY Loves Math 莫比乌斯反演+打表

    有一个神奇的技巧——打表 code: #include <bits/stdc++.h> #define N 10000007 #define ll long long #define se ...

  5. 【BZOJ】3309: DZY Loves Math 莫比乌斯反演优化

    3309: DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007) ...

  6. ●BZOJ 3309 DZY Loves Math

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...

  7. BZOJ 3309: DZY Loves Math

    3309: DZY Loves Math Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 761  Solved: 401[Submit][Status ...

  8. 【BZOJ3309】DZY Loves Math 莫比乌斯反演+线性筛(好题)

    [BZOJ3309]DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10 ...

  9. 【BZOJ3309】DZY Loves Math - 莫比乌斯反演

    题意: 对于正整数n,定义$f(n)$为$n$所含质因子的最大幂指数.例如$f(1960)=f(2^3 * 5^1 * 7^2)=3$,$f(10007)=1$,$f(1)=0$. 给定正整数$a,b ...

随机推荐

  1. ubuntu16 升级pip3后报错File "/usr/bin/pip3", line 9, in <module> from pip import main ImportError: cannot import name 'main'

    问题:ubuntu16 执行pip3 install --upgrade pip之后,pip3执行出错. Traceback (most recent call last): File "/ ...

  2. php实现当前页面点击下载文件的实例

    php控制器中代码 public function downFile($path = ''){     if(!$path) header("Location: /");      ...

  3. LINUX操作系统知识:进程与线程详解

    当一个程序开始执行后,在开始执行到执行完毕退出这段时间内,它在内存中的部分就叫称作一个进程. Linux 是一个多任务的操作系统,也就是说,在同一时间内,可以有多个进程同时执行.我们大家常用的单CPU ...

  4. python中的文件操作小结2

    ''' #-----------文件修改---------- f=open("test_1",'r',encoding="utf-8") f2=open(&qu ...

  5. python pycharm2018开启debug模式

    为什么需要开启DEBUG模式1.如果开启了DEBUG模式,那么在代码中如果抛出了异常,在浏览器的页面中可以看到具体的错误信息,以及具体的错误代码位置,方便开发者调试.2.如果开启DEBUG模式,那么以 ...

  6. 裸机——iNand

    1.先晓得iNand的基础知识 iNand是在SD卡基础上发展来的,而SD卡是在MMC的基础上发展来的,MMC是在Nand的基础上发展来的 我们晓得Nand的基础知识,而MMC对Nand大致做了两个改 ...

  7. POJ-2251 三维迷宫

    题目大意:给一个三维图,可以前后左右上下6种走法,走一步1分钟,求最少时间(其实就是最短路) 分析:这里与二维迷宫是一样的,只是多了2个方向可走,BFS就行(注意到DFS的话复杂度为O(6^n)肯定会 ...

  8. POJ:2236-Wireless Network

    Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 34265 Accepted: 14222 D ...

  9. 陌生又熟悉的数据库之ID增加

    当我们设计一张表时,通常为了保证记录的唯一性,会为表增加一个ID字段,生成记录时ID自动加一

  10. 笔记-python lib-pymongo

    笔记-python lib-pymongo 1.      开始 pymongo是python版的连接库,最新版为3.7.2. 文档地址:https://pypi.org/project/pymong ...