3309: DZY Loves Math

Time Limit: 20 Sec  Memory Limit: 512 MB
Submit: 1240  Solved: 777
[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

1<=a,b<=10^7

 #include<bits/stdc++.h>
#define rint register int
#define N 10000001
using namespace std;
int cnt,sum[N],a[N],b[N],p[N>>],vis[N]; int main(){
for(rint i=;i<N;++i){
if(!vis[i]){p[++cnt]=i;a[i]=sum[i]=;b[i]=i;}
for(rint j=;j<=cnt&&p[j]*i<N;++j){
static int k,t;k=p[j]*i;vis[k]=;
if(i%p[j]){a[k]=;b[k]=p[j];sum[k]= a[i]==?-sum[i]:;}
else{
a[k]=a[i]+;b[k]=b[i]*p[j];t=i/b[i];
if(t==)sum[k]=;else sum[k]= a[t]==a[k]?-sum[t]:;
break;
}
}
}
for(rint i=;i<N;++i)sum[i]+=sum[i-];
int T,n,m,pos;long long ans;scanf("%d",&T);
for(rint c=;c<=T;++c){
scanf("%d%d",&n,&m);
if(n>m)swap(n,m);ans=;
for(rint i=;i<=n;i=pos+){
pos=min(n/(n/i),m/(m/i));
ans+=1ll*(n/i)*(m/i)*(sum[pos]-sum[i-]);
}
printf("%lld\n",ans);
}
return ;
}

bzoj3309DZY Loves Math的更多相关文章

  1. BZOJ 3309: DZY Loves Math

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

  2. HDU 5675 ztr loves math (数学推导)

    ztr loves math 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/A Description ztr loves re ...

  3. HDU 5675 ztr loves math

    ztr loves math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. 【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) ...

  5. [BZOJ3561] DZY Loves Math VI

    (14.10.28改) 本来只想写BZOJ3739:DZY Loves Math VIII的,不过因为和VI有关系,而且也没别人写过VI的题解,那么写下. 不过我还不会插公式…… http://www ...

  6. BZOJ 3512: DZY Loves Math IV [杜教筛]

    3512: DZY Loves Math IV 题意:求\(\sum_{i=1}^n \sum_{j=1}^m \varphi(ij)\),\(n \le 10^5, m \le 10^9\) n较小 ...

  7. ●BZOJ 3309 DZY Loves Math

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

  8. bzoj3561DZY Loves Math VI

    3561: DZY Loves Math VI Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 503  Solved: 333[Submit][Sta ...

  9. DZY Loves Math 系列详细题解

    BZOJ 3309: DZY Loves Math I 题意 \(f(n)\) 为 \(n\) 幂指数的最大值. \[ \sum_{i = 1}^{a} \sum_{j = 1}^{b} f(\gcd ...

随机推荐

  1. io多路复用(三)

    #!/usr/bin/env python # -*- coding:utf-8 -*- import socket sk1 = socket.socket() sk1.bind(('127.0.0. ...

  2. bzoj 4399 魔法少女LJJ

    4399: 魔法少女LJJ Time Limit: 20 Sec  Memory Limit: 162 MBhttp://www.lydsy.com/JudgeOnline/problem.php?i ...

  3. display属性

    display 属性规定元素应该生成的框的类型. 值 描述 none 此元素不会被显示. block 此元素将显示为块级元素,此元素前后会带有换行符. inline 默认.此元素会被显示为内联元素,元 ...

  4. [Redis源码阅读]redis持久化

    作为web开发的一员,相信大家的面试经历里少不了会遇到这个问题:redis是怎么做持久化的? 不急着给出答案,先停下来思考一下,然后再看看下面的介绍.希望看了这边文章后,你能够回答这个问题. 为什么需 ...

  5. Python之旅.第三章.函数3.26

    一.函数: 1.为什么要有函数?什么是函数? 1.组织结构不清晰,可读性差 2.代码冗余 3.管理维护的难度极大,扩展性 具备某一个功能的工具就是程序的中函数 事先准备工具的过程---->函数的 ...

  6. Python内置函数(41)——id

    英文文档: id(object) Return the "identity" of an object. This is an integer which is guarantee ...

  7. linux 下 /bin /sbin 的区别

    /bin,/sbin,/usr/bin,/usr/sbin区别 /  : this is root directory                root 用户根目录 /bin : command ...

  8. istio入门(03)istio的helloworld-场景说明

    一.原生应用 四个微服务: python微服务:一个deployment(deployment含有一个pod,pod内含有一个容器) java微服务:三个deployment(deployment含有 ...

  9. OAuth2.0学习(1-3)OAuth2.0的参与者和流程

    OAuth(开放授权)是一个开放标准.允许第三方网站在用户授权的前提下访问在用户在服务商那里存储的各种信息.而这种授权无需将用户提供用户名和密码提供给该第三方网站. OAuth允许用户提供一个令牌给第 ...

  10. apigw鉴权分析(1-1)阿里数加 - 鉴权方式分析

    一.访问方式 1.访问阿里云首页 https://www.aliyun.com/?utm_medium=text&utm_source=bdbrand&utm_campaign=bdb ...