ACM学习历程—FZU2191完美的数字(数学)

Description

Bob是个很喜欢数字的孩子,现在他正在研究一个与数字相关的题目,我们知道一个数字的完美度是 把这个数字分解成三个整数相乘A*A*B(0<A<=B)的方法数,例如数字80可以分解成1*1*80,2*2*20 ,4*4*5,所以80的完美度是3;数字5只有一种分解方法1*1*5,所以完美度是1,假设数字x的完美度为d(x),现在给定a,b(a<=b),请你帮Bob求出

S,S表示的是从a到b的所有数字的流行度之和,即S=d(a)+d(a+1)+…+d(b)。

Input

输入两个整数a,b(1<=a<=b<=10^15)

Output

输出一个整数,表示从a到b的所有数字流行度之和。

Sample Input

1 80

Sample Output

107

题目要求a到b区间内,d(i)的和。

而d(i)表示i能拆分成A*A*B形式的种数,A<=B

首先直接要求i的拆分需要暴力枚举的话,复杂度是很大的。

于是考虑到i = A*A*B的话,对于一组满足条件的(A, B)就需要对d(i)++,d(i)初值为0.

但是这样的话还是需要从小到大枚举A,并枚举B,求出所有区间内的d(i)。

但是题目要求的是和。

这样的话有一部是可以优化就是我们最后求的和就是每次++的和,因为d初值为0。

那么我枚举到某个A的时候,有多少个满足条件的B,就需要++多少次。也就是只需要得到一个上界和下届,一减就得到了。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#define LL long long

using namespace std;

const int maxN = 1e5;
LL a, b;

LL myMax(LL x, LL y)
{
    return x > y ? x : y;
}

void work()
{
    LL x, y, ans = 0;
    for (LL k = 1; k <= maxN && k*k*k <= b; ++k)
    {
        if (a%(k*k) == 0)
            x = a/(k*k);
        else
            x = a/(k*k)+1;
        x = myMax(x, k);
        y = b/(k*k);
        ans += y-x+1;
    }
    printf("%I64d\n", ans);
}

int main()
{
    //freopen("test.in", "r", stdin);
    while (scanf("%I64d%I64d", &a, &b) != EOF)
    {
        work();
    }
    return 0;
}
时间: 2024-10-18 15:06:02

ACM学习历程—FZU2191完美的数字(数学)的相关文章

ACM学习历程—51NOD 1770数数字(循环节)

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1770 这是这次BSG白山极客挑战赛的A题.由于数字全部相同,乘上b必然会有循环节,于是模拟乘法,记录数据,出现循环就退出即可. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring>

ACM学习历程—HDU 5073 Galaxy(数学)

Description Good news for us: to release the financial pressure, the government started selling galaxies and we can buy them from now on! The first one who bought a galaxy was Tianming Yun and he gave it to Xin Cheng as a present. To be fashionable,

ACM学习历程—UESTC 1226 Huatuo&#39;s Medicine(数学)(2015CCPC L)

题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #

ACM学习历程—HDU 4726 Kia&#39;s Calculation( 贪心&amp;&amp;计数排序)

DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number when the sum of two digits exceeds 9. For example, when she calculates 4567+5789, she will get 9246, and for 12

ACM学习历程—HDU 5023 A Corrupt Mayor&#39;s Performance Art(广州赛区网赛)(线段树)

Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed a safe way for mayor X to make money. Becaus

ACM学习历程—HDU1030 Delta-wave(数学)

Description A triangle field is numbered with successive integers in the way shown on the picture below. The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only,

ACM学习历程—HDU5587 Array(数学 &amp;&amp; 二分 &amp;&amp; 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后从0到末尾,每一个都加上1. 例如:a0, a1, a2 => a0, a1, a2, 1, a0+1, a1+1, a2+1 题解中是这么说的:“ 其实Ai为i二进制中1的个数.每次变化A{k+2^i}=A{k}+1,(k<2^?i??)不产生进位,二进制1的个数加1.然后数位dp统计前m个数二

ACM学习历程—HDU5490 Simple Matrix (数学 &amp;&amp; 逆元 &amp;&amp; 快速幂) (2015合肥网赛07)

Problem Description As we know, sequence in the form of an=a1+(n−1)d is called arithmetic progression and sequence in the form of bn=b1qn−1(q>1,b1≠0) is called geometric progression. Huazheng wants to use these two simple sequences to generate a simp

ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)

Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess with his friends. What's more, he bought a large decorative chessboard with N rows and M columns. Every day after work, Edward will place