Description
Bob is a kid who likes numbers, and now he's working on a number-related topic, and we know that the perfect degree of a number is the number of methods that divide this number into three integers multiplied by a*a*b (0<a<=b), such as the number 80 can be decomposed into 1*1*80,2*2*20, 4*5, so the perfect degree of 80 is 3; The number 5 has only one decomposition method 1*1*5, so the perfect degree is 1, assuming the digital x is the perfect degree of D (x), now given a B (a<=b), please help Bob to find out
S,s represents the sum of the prevalence of all numbers from a to B, i.e. S=d (a) +d (a+1) +...+d (b).
Input
Enter two integers, a, B (1<=a<=b<=10^15)
Output
Outputs an integer that represents the sum of all digital popularity from A to B.
Sample Input
1 80
Sample Output
107
The topic requires a to B range, and D (i) of the and.
and d (i) means I can be split into a*a*b form, a<=b
The complexity is very large if the split of I requires a violent enumeration first.
So considering i = a*a*b, the initial value of D (i) ++,d (i) is 0 for a set of satisfying conditions (a, B).
However, it is necessary to enumerate a from small to large and enumerate B to find D (i) in all intervals.
But the subject is the same as.
In this case, one of the things that can be optimized is our last request and that is, each + +, because D has an initial value of 0.
So when I enumerate to a A, how many times can I have a B that satisfies the condition? That is, just need to get an upper bound and next, one minus on the get.
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<Set>#include<map>#include<queue>#include<string>#include<algorithm>#defineLL Long Longusing namespacestd;Const intMAXN =1e5; LL A, B; ll Mymax (ll X, ll y) {returnx > y?x:y;}voidWork () {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); Elsex= A/(K*K) +1; X=Mymax (x, k); Y= b/(k*k); Ans+ = y-x+1; } printf ("%i64d\n", ans);}intMain () {//freopen ("test.in", "R", stdin); while(SCANF ("%i64d%i64d", &a, &b)! =EOF) {work (); } return 0;}
ACM Learning process-fzu2191 Perfect numbers (math)