Nastya Studies Informatics
 
time limit per test

1 second

 
memory limit per test

256 megabytes

 
input

standard input

output

standard output

 

Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.

We define a pair of integers (a,b)good, if GCD(a,b)=x and LCM(a,b)=y, where GCD(a,b)denotes the greatest common divisor of a and b, and LCM(a,b)denotes the least common multiple of a and b.

You are given two integers x and y. You are to find the number of good pairs of integers (a,b) such that l≤a,b≤r. Note that pairs (a,b) and (b,a) are considered different if a≠b.

Input

The only line contains four integers l,r,x,y (1≤l≤r≤109, 1≤x≤y≤109).

Output

In the only line print the only integer — the answer for the problem.

Examples
input
1 2 1 2
output
2
input
1 12 1 12
output
4
input
50 100 3 30
output
0
Note

In the first example there are two suitable good pairs of integers (a,b): (1,2) and (2,1).

In the second example there are four suitable good pairs of integers (a,b): (1,12), (12,1),(3,4) and(4,3).

In the third example there are good pairs of integers, for example, (3,30), but none of them fits the condition l≤a,b≤rl≤a,b≤r.


题意就是给你一个范围(l,r),让你找有多少个数对(a,b)满足a和b的最大公约数是x,最小公倍数是y

思路就是对x,y进行质因数分解,这样对于每一个质因数,就会有一个上界和一个下界,而a,b对应的质因数取值也只能取上界或者下界

这样就可以把所有满足条件的数对都找出来,然后再一个个的判断是否在(l,r)范围里。

很显然数对的个数不会超过2的二十次方左右,所以不会超时。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#define N 1000005
using namespace std; long long prime[N+],len=,pd[N+]= {}; void shushu()
{
pd[]=pd[]=; for(int i=; i<=N; i++)
{
if(pd[i]==)
{
prime[len++]=i;
} for(int j=; j<len; j++)
{
if(i*prime[j]>=N)
break;
pd[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
} long long l,r,x,y,team[],team1[]= {},team2[]= {},c1=,ans=; long long ff(long long a,long long b);
void f(long long x,long long a,long long b)
{ if(x==c1)
{
if(a>=l&&a<=r&&b>=l&&b<=r)
{
ans++; } return;
}
f(x+,a,b); if(team1[x]!=team2[x])
f(x+,a/ff(team[x],team1[x])*ff(team[x],team2[x]),b/ff(team[x],team2[x])*ff(team[x],team1[x])); } long long ff(long long a,long long b)
{
long long ans=; while(b>)
{
if(b%==)
{
ans*=a; } a*=a;
b/=; }
return ans;
} int main()
{
shushu(); scanf("%I64d %I64d %I64d %I64d",&l,&r,&x,&y); if(y%x!=)
{
printf("");
return ;
} for(int i=; i<len; i++)
{
if(y%prime[i]==)
team[c1++]=prime[i]; while(y%prime[i]==)
{
team2[c1-]++;
y/=prime[i]; } } if(y>)
{
team[c1++]=y;
team2[c1-]++;
} for(int i=; i<c1; i++)
{
while(x%team[i]==)
{
team1[i]++;
x/=team[i];
}
} long long a=,b=; for(int i=; i<c1; i++)
a*=ff(team[i],team1[i]);
for(int i=; i<c1; i++)
b*=ff(team[i],team2[i]); f(,a,b);
printf("%I64d",ans);
return ;
}

Nastya Studies Informatics的更多相关文章

  1. Nastya Studies Informatics CodeForces - 992B (大整数)

    B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input ...

  2. CF992B Nastya Studies Informatics 数学(因子) 暴力求解 第三道

    Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input st ...

  3. Nastya Studies Informatics CodeForces - 992B(增长姿势)

    有增长姿势了 如果a * b == lcm * gcd 那么a和b为lcm因数  这个我之前真不知道emm... #include <bits/stdc++.h> #define mem( ...

  4. 【Codeforces 992B】Nastya Studies Informatics

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 因为gcd(a,b)=x 所以设a = nx b = mx 又有ab/gcd(a,b)=lcm(a,b)=y 则nmx = y 即n(m*x) ...

  5. CodeForces 992B Nastya Studies Informatics + Hankson的趣味题(gcd、lcm)

    http://codeforces.com/problemset/problem/992/B  题意: 给你区间[l,r]和x,y 问你区间中有多少个数对 (a,b) 使得 gcd(a,b)=x lc ...

  6. Codeforces Round #489 (Div. 2)

    A. Nastya and an Array time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #489 (Div. 2) B、C

    B. Nastya Studies Informatics time limit per test 1 second memory limit per test 256 megabytes input ...

  8. [Codeforces]Codeforces Round #489 (Div. 2)

    Nastya and an Array 输出有几种不同的数字 #pragma comment(linker, "/STACK:102400000,102400000") #ifnd ...

  9. Codeforces Round #546 (Div. 2) C. Nastya Is Transposing Matrices

    C. Nastya Is Transposing Matrices time limit per test 1 second memory limit per test 256 megabytes i ...

随机推荐

  1. 洛谷 2543 [AHOI2004]奇怪的字符串

    题目描述 输入输出格式 输入格式: 输入文件中包含两个字符串X和Y.当中两字符串非0即1.序列长度均小于9999. 输出格式: X和Y的最长公共子序列长度. 输入输出样例 输入样例#1: 010101 ...

  2. Linux内核漏洞利用-环境配置(转)

    实验环境: Ubuntu-14.04.1 x86 linux-2.6.32.1 busybox-1.27.2 qemu 0x00 安装qemu sudo apt-get install qemu qe ...

  3. House of Spirit(fastbin)

    0x01 fastbin fastbin所包含chunk的大小为16 Bytes, 24 Bytes, 32 Bytes, … , 80 Bytes.当分配一块较小的内存(mem<=64 Byt ...

  4. 什么是无符号段整数,什么又是有符号数,(c++与java语言里边的不同)

    c++中:整型数分为有符号数和无符号数两种 unsigned int a;无符号整型变量a,意思是这个数最小值为0,最大值为2的32次方-1,因为一个整型数占四个字节,一个字节8位,共32位 int ...

  5. Linux菜鸟起飞之路【二】Linux基本常识

    一.Unix操作系统基本常识 1.什么是Unix? Unix是一个计算机操作系统,是一个用来协调.管理和控制计算机硬件与软件资源的控制程序. 2.Unix操作系统的特点? 多用户与多任务.多用户表示在 ...

  6. docker系列之安装配置-2

    1.docker安装 1.CentOS Docker 安装 Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 目前,C ...

  7. 如何用纯 CSS 创作背景色块变换的按钮特效

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/XYKdwg 可交互视频教 ...

  8. 我的Python分析成长之路9

    pandas入门 统计分析是数据分析的重要组成部分,它几乎贯穿整个数据分析的流程.运用统计方法,将定量与定性结合,进行的研究活动叫做统计分析.而pandas是统计分析的重要库. 1.pandas数据结 ...

  9. set的应用:UVa10815-Andy's First Dictionary

    Andy's First Dictionary Andy, 8, has a dream - he wants to produce his very own dictionary. This is ...

  10. PAT Basic 1066

    1066 图像过滤 图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来.现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换. 输入格式: 输入在第一 ...