SHLQSH数

The first question  SHLQSHnumber

                                                                       (Shlqsh.pas / c / cpp)

【Problem Description】

We t1, t2 ( including t1, t2 (1 <= t1 <t2 <= 10000000)) number divisor of all numbers between and n is called t1, t2 of shlqsh number ;

The problem is that given the data t1, t2 after , seeking t1, t2 of shlqsh number;

[Input Format]

Input file shlqsh.in contain only one row, a total of two integers representing t1 t2 ( separated by spaces )

 

[Output format]

Output file shlqsh.out only an integer representing t1, t2 between shlqsh number.

 

[Sample input]

2 6

[Sample Output]

13

   Sample Description: ( Description section need not output )

            2 divisors are 1,2 (2 th ) ;

            3 divisors are 1,3 (2 th ) ;

            4 divisors are 2,4 (3 th ) ;

            5 divisors are 1,5 (2 th ) ;

            6 divisors are 1,2,3,6 (4 th ) .

Therefore 26 of shlqsh number 13

[Data] scale

    For 50% of the data , ensure t1, t2 <= 5000000

    For all the data , ensure t1, t2 <= 10000000

 

 

 

 

【problem analysis】

Let's consider this question:

Seeking n and all of the following positive integer divisible by I (1 <= <= n I) the counted number of the number;

Is not consider using I n div it ? Yes.

Then we enumerate (1..n) the I , the n div I accumulated into a temporary variable tot in, get what?

To give a n number of divisors and all of the following numbers and.

For example: when n = 6 when ;

begin

to: = 0;

for I:=1 to n do inc(tot,n div i);

writeln(tot);

       end.

Result tot = 14;

1 divisors are 1 ;

2 divisors are 1 , 2 ;

3 divisors are 1 , 3 ;

4 divisors are 1 , 2 , 4 ;

5 divisors are 1 , 5 ;

6 divisors are 1 , 2 , 3 , 6 ;

A total of 14 ! ( Just as tot)

Please think about why?


      
Back to this question:

 Seeking t1, t2 between the number of the divisor and the number of all n- ;

 We can consider seeking (t1-1) and the following ~~

             Then seek t2  and below ~~~

 Then subtract; OK !!!

 

#include<stdio.h>
#include<stdlib.h>
long t1,t2,a,i;
int main(){
    freopen("shlqsh.in","r",stdin);
    freopen("shlqsh.out","w",stdout);
    scanf("%ld%ld",&t1,&t2);   
    t1--;
    for (i=1;i<=t1;i++) a-=t1/i;
    for (i=1;i<=t2;i++) a+=t2/i;
    printf("%ld",a);   
    return 0;
}

 

 

Reproduced in: https: //www.cnblogs.com/yanrui7098/archive/2009/11/19/1606122.html

Guess you like

Origin blog.csdn.net/weixin_34289454/article/details/94508904