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. python__系统 : socket_UDP相关

    socket.socket() 可以创建一个套接字: from socket import * from threading import Thread udp_socket = None dest_ ...

  2. P1582倒水 位运算

    题目描述 一天,CC买了N个容量可以认为是无限大的瓶子,开始时每个瓶子里有1升水.接着~~CC发现瓶子实在太多了,于是他决定保留不超过K个瓶子.每次他选择两个当前含水量相同的瓶子,把一个瓶子的水全部倒 ...

  3. 适合pc端的移动拖拽,分享一下。

    h5新加的特性拖拽事件,但是只适合PC端哦.不多说了上代码 <!DOCTYPE html> <html> <head> <title></titl ...

  4. 4034: [HAOI2015]树上操作

    4034: [HAOI2015]树上操作 链接 思路: 树链剖分.操作:单点修改,路径查询,子树修改. 代码: #include<cstdio> #include<algorithm ...

  5. laravel5.5服务提供器

    目录 1. 编写服务提供器 1.1 注册方法 register 1.1.1 简单绑定 1.1.2 绑定单例 1.1.3 绑定实例 1.1.4 绑定初始数据 1.2 引导方法 boot 2. 注册服务提 ...

  6. MyEclipse - 问题集 - build properties does not exist

    方案1 受MyEclipse生成的项目文件.project影响,检查其中是否含有“<nature>org.eclipse.pde.PluginNature</nature>”, ...

  7. iOS系统信息集合

    在项目开发的时候,经常需要用到某些系统信息,比如手机型号(5s,6,6p), 操作系统版本(8.0 or 9.3), 当前网络类型(3/4g, wifi)等信息. 有了这些信息, 可以在出了某些bug ...

  8. 【情人节礼物】纯js脚本打造精美3D玫瑰

    情人节就要来临了,这是用代码做出的玫瑰花,这才是程序员送给女友的最好情人节礼物...(提示:在不同浏览器下观看效果.速度会有很大的不同) 代码如下: <!doctype html> < ...

  9. Java基础-6流程控制

    一).选择控制: 选择控制分为两种:if...else...和switch 单分支结构:这是最简单的一种选择结构,它只是简单的判断某个条件是否成立,如果成立就执行一段代码,语句形式为: if(条件表达 ...

  10. python 之发送邮件服务[原著] 海瑞博客

    Python 发送邮件 使用默认的django的发送邮件,只适用于单邮箱. 作者:海瑞博客 http://www.hairuinet.com/ setting中配置 # send e-mail EMA ...