Mophues

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others)
Total Submission(s): 579    Accepted Submission(s): 235

Problem Description
As we know, any positive integer C ( C >= 2 ) can be written as the multiply of some prime numbers:
    C = p1×p2× p3× ... × pk
which p1, p2 ... pk are all prime numbers.For example, if C = 24, then:
    24 = 2 × 2 × 2 × 3
    here, p1 = p2 = p3 = 2, p4 = 3, k = 4

Given two integers P and C. if k<=P( k is the number of C's prime factors), we call C a lucky number of P.

Now, XXX needs to count the number of pairs (a, b), which 1<=a<=n , 1<=b<=m, and gcd(a,b) is a lucky number of a given P ( "gcd" means "greatest common divisor").

Please note that we define 1 as lucky number of any non-negative integers because 1 has no prime factor.

 
Input
The first line of input is an integer Q meaning that there are Q test cases.
Then Q lines follow, each line is a test case and each test case contains three non-negative numbers: n, m and P (n, m, P <= 5×105. Q <=5000).
 
Output
For each test case, print the number of pairs (a, b), which 1<=a<=n , 1<=b<=m, and gcd(a,b) is a lucky number of P.
 
Sample Input
2
10 10 0
10 10 1
 
Sample Output
63
93
 
Source
 
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; typedef __int64 LL;
const int maxn=*1e5+;
int prime[maxn],mu[maxn],num,cnt[maxn],mbs[maxn][];
bool flag[maxn];
void swap(int &a,int &b){ int t=a;a=b;b=t;}
int min(int a,int b){return a<b?a:b;} void init()
{
int i,j;
mu[]=;cnt[]=;
memset(flag,true,sizeof(flag));
for(i=;i<maxn;i++)
{
if(flag[i])
{
prime[num++]=i;mu[i]=-;cnt[i]=;
}
for(j=;j<num&&i*prime[j]<maxn;j++)
{
flag[i*prime[j]]=false;
cnt[i*prime[j]]=cnt[i]+;
if(i%prime[j]==)
{
mu[i*prime[j]]=;break;
}
else mu[i*prime[j]]=-mu[i];
}
}
memset(mbs,,sizeof(mbs));
for(i=;i<maxn;i++)//求出单项的mbs[i][j],表示的是i为公因子时的情况。
for(j=i;j<maxn;j+=i)
mbs[j][cnt[i]]+=mu[j/i];
for(i=;i<maxn;i++) //以下是求前缀和
for(j=;j<;j++)
mbs[i][j]+=mbs[i-][j];
for(i=;i<maxn;i++)
for(j=;j<;j ++)
mbs[i][j]+=mbs[i][j-];
} int main()
{
num=;
init();
int i,j,t,n,m,p;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&n,&m,&p);
if(p>=){ printf("%I64d\n",(LL)n*m);continue;}
if(n>m) swap(n,m);
LL ans=;
for(i=,j=;i<n;i=j+)
{
j=min(n/(n/i),m/(m/i));
ans+=(LL)(mbs[j][p]-mbs[i-][p])*(n/i)*(m/i);
}
printf("%I64d\n",ans);
}
return ;
}

hud 4746 莫比乌斯反演的更多相关文章

  1. HDU 4746 (莫比乌斯反演) Mophues

    这道题看巨巨的题解看了好久,好久.. 本文转自hdu4746(莫比乌斯反演) 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<= ...

  2. HDU 4746 莫比乌斯反演+离线查询+树状数组

    题目大意: 一个数字组成一堆素因子的乘积,如果一个数字的素因子个数(同样的素因子也要多次计数)小于等于P,那么就称这个数是P的幸运数 多次询问1<=x<=n,1<=y<=m,P ...

  3. HDU 4746 Mophues (莫比乌斯反演应用)

    Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total ...

  4. HDU 4746 Mophues【莫比乌斯反演】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4746 题意: 1≤x,y≤n , 求gcd(x,y)分解后质因数个数小于等k的(x,y)的对数. 分 ...

  5. Mophues HDU - 4746 (莫比乌斯反演)

    Mophues \[ Time Limit: 10000 ms\quad Memory Limit: 262144 kB \] 题意 求出满足 \(gcd\left(a,b\right) = k\), ...

  6. HDU 4746 Mophues(莫比乌斯反演)题解

    题意: \(Q\leq5000\)次询问,每次问你有多少对\((x,y)\)满足\(x\in[1,n],y\in[1,m]\)且\(gcd(x,y)\)的质因数分解个数小于等于\(p\).\(n,m, ...

  7. hdu1695 GCD(莫比乌斯反演)

    题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...

  8. BZOJ 2154: Crash的数字表格 [莫比乌斯反演]

    2154: Crash的数字表格 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 2924  Solved: 1091[Submit][Status][ ...

  9. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

随机推荐

  1. PAT (Basic Level) Practise (中文)- 1013. 数素数 (20)

    http://www.patest.cn/contests/pat-b-practise/1013 令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有 ...

  2. 用C#(ASP.Net)在Exchange Server环境下发送邮件

    普通的邮件, 用System.Net.Mail 类 或 System.Web.Mail 类 处理即可, 但是Exchange Server 环境下, 这两个类起不了作用-------至少目前我看到的情 ...

  3. Bootstrap历练实例:向列表组添加链接

    向列表组添加链接 通过使用锚标签代替列表项,我们可以向列表组添加链接.我们需要使用 <div> 代替 <ul> 元素.下面的实例演示了这点: <!DOCTYPE html ...

  4. 个人对spring的IOC+DI的封装

    暂时支持8种基本数据类型,String类型,引用类型,List的注入. 核心代码 package day01; import java.lang.reflect.Field;import java.l ...

  5. mutt+msmtp做linux邮件客户端

    mutt+msmtp做linux邮件客户端 1. 安装配置msmtp l  安装 wget https://sourceforge.net/projects/msmtp/files/msmtp/1.4 ...

  6. ssh整合思想 Spring与Hibernate和Struts2的action整合 调用action添加数据库 使用HibernateTemplate的save(entity)方法 update delete get 等方法crud操作

    UserAction类代码: package com.swift.action; import com.opensymphony.xwork2.ActionSupport; import com.sw ...

  7. PAT 乙级 1088

    题目 题目链接:PAT 乙级 1088 题解 比较简单的一道题,下面来简单说说思路: 因为甲确定是一个两位数,因此通过简单的暴力循环求解甲的值,又根据题设条件“把甲的能力值的 2 个数字调换位置就是乙 ...

  8. python入门:求1-2+3-4+5...99的所有数的和(自写)

    #!/usr/bin/env pyhton # -*- coding:utf-8 -*- #求1-2+3-4+5...99的所有数的和(自写) """ 给x赋值为0,给y ...

  9. pandas-Notes1

    #coding = utf-8 import pandas as pd import numpy as np import matplotlib as plt # series, like vecto ...

  10. SQL登录注册练习

    /class User package com.neusoft.bean; public class User { private int password; private String name; ...