【数学题】SHLQSH数

 SHLQSH数

 问题描述:

我们把t1 , t2 (包括t1 , t2 (1<=t1<t2<=10000000))之间的所有数的约数个数和n称为t1 , t2的shlqsh数;

问题是给出数据t1 , t2后,求t1 , t2的shlqsh数;

 

输入

输入文件 shlqsh.in 仅包含一行,共有两个整数,表示t1 t2 (用空格分开)

 

输出

输出文件shlqsh.out 仅有一个整数,表示t1 , t2之间的shlqsh数。

 

输入样例:

2 6

 

输出样例:

13

   样例说明:(说明部分不必输出)

            2的约数有1,2 (2个);

            3的约数有1,3 (2个);

            4的约数有1,2,4 (3个);

            5的约数有1,5 (2个);

            6的约数有1,2,3,6 (4个)。

所以2 6 的shlqsh数为13

【数据规模】

    对于50 %的数据,保证有t1,t2<=5000000

    对于全部的数据,保证有t1,t2<=10000000

======================================

老师在考试的时候说。。下午讲题的时候..看着这道题的代码很多人要吐血..

..果然...

求每个数的约数..若枚举每个数.这枚举量太大了...

应该枚举每个数的约束..累加约数和...这样O(N)的复杂度就可以OK了..

========================

var
  t1,t2:longint;
procedure init;
begin
  assign(input,'shlqsh.in');
  assign(output,'shlqsh.out');
  reset(input); rewrite(output);
end;

procedure terminate;
begin
  close(input); close(output);
  halt;
end;

procedure main;
var
  i,j:longint;
  ans:longint;
  t:longint;
begin
 readln(t1,t2);
 ans:=0;
 for i:=1 to t2 do
   ans:=ans+t2 div i;
 for i:=1 to t1-1 do
   ans:=ans-(t1-1) div i;
 writeln(ans);
end;

begin
  init;
  main;
  terminate;
end.


=======================================

附打表程序..只过了8个点..主要是学习打表方法..若把表打密一点就可以过了..

====

const
  biao:array[0..100]of longint=
      (0,1166750,2472113,3829833,5221472,6638449,8075504,
         9529316,10997454,12478206,13970034,15471834,
         16982741,18502034,20029013,21563172,23103918,
         24650975,26203975,27762428,29326296,30895025,
         32468539,34046648,35629007,37215589,38806214,
         40400725,41998809,43600482,45205760,46814198,
         48425926,50040880,51658667,53279454,54903203,
         56529611,58158815,59790632,61425110,63061872,
         64701179,66342791,67986865,69633203,71281688,
         72932251,74585102,76240071,77896938,79555864,
         81216802,82879546,84544347,86210861,87879246,
         89549371,91221198,92894942,94570325,96247243,
         97925867,99606221,101287993,102971423,104656393,
         106342746,108030713,109720250,111411029,113103244,
         114797007,116492131,118188494,119886288,121585508,
         123285988,124987758,126690768,128395238,130100774,
         131807479,133515444,135224718,136935081,138646648,
         140359419,142073346,143788415,145504640,147221752,
         148940245,150659679,152380115,154101766,155824418,
         157548020,159272878,160998658,162725364);
procedure init;
begin
  assign(input,'shlqsh.in');
  assign(output,'shlqsh.out');
  reset(input); rewrite(output);
end;

procedure terminate;
begin
  close(input); close(output);
  halt;
end;

function calc(x:longint):longint;
var
  i,j:longint;
  t:longint;
begin
   calc:=0;
   for i:=(x div 100000)*100000+1 to x do
    begin
      t:=0;
      for j:=1 to trunc(sqrt(i)) do
        begin
          if i mod j=0 then inc(t);
        end;
      if trunc(sqrt(i))*trunc(sqrt(i))=i then calc:=calc+t*2-1
                                         else calc:=calc+t*2;
    end;
end;

procedure main;
var
  a,b:longint;
  ans1,ans2:longint;
  i:longint;
begin
  readln(a,b);
  ans1:=biao[(a-1)div 100000]+calc(a-1);
  ans2:=biao[b div 100000]+calc(b);
  writeln(ans2-ans1);
end;

begin
  init;
  main;
  terminate;
end.


 

 

 

 

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页