zoukankan      html  css  js  c++  java
  • 格点统计

    Description
    这里写图片描述

    Input
    这里写图片描述

    Output
    这里写图片描述

    Sample Input

    输入1:
    3
    输入2:
    4

    Sample Output

    输出1:
    5
    这里写图片描述

    输出2:
    8


    Data Constraint
    这里写图片描述
    .
    .
    .
    .
    .
    .
    .
    .

    分析

    这题就是让我们求,在一个坐标系里,有多少个坐标(x,y)相乘小于等于k,即:x*y<=k


    当k=4时,所求点如下:
    这里写图片描述
    观察图,我们可以发现,对于第i行,它的个数是trunc(k/i),即k div i。
    因此,我们可以枚举i(i=1 to k)来求ans,但由于k的数据过大,i=1 to k会超时。
    .
    .
    .
    .
    让我们再仔细观察图 :
    这里写图片描述
    我们发现,当我们求出第一行时,第一列也会求出来
    因此,我们有了一种想法:
    枚举i( i=1 to trunc(sqrt(k)) )
    每求出一行,就把数量乘2(因为会有重叠的地方,所以要减去重叠的地方乘2)累加

    记得取模

    .
    .
    .
    .
    .
    .
    .

    程序:
    var
    k,ans:qword;
    i:longint;
    begin
        assign(input,'count.in');
        reset(input);
        assign(output,'count.out');
        rewrite(output);
        read(k);
        ans:=0;
        for i:=1 to trunc(sqrt(k)) do
        ans:=(ans+(trunc(k/i)-(i-1))*2-1) mod 998244353;
        write(ans);
        close(input);
        close(output);
    end.
    
  • 相关阅读:
    Binary Tree Inorder Traversal
    Populating Next Right Pointers in Each Node
    Minimum Depth of Binary Tree
    Majority Element
    Excel Sheet Column Number
    Reverse Bits
    Happy Number
    House Robber
    Remove Linked List Elements
    Contains Duplicate
  • 原文地址:https://www.cnblogs.com/YYC-0304/p/9499990.html
Copyright © 2011-2022 走看看