zoukankan      html  css  js  c++  java
  • 【数学 思维题】HDU4473Exam

    过程很美妙啊

    Problem Description

    Rikka is a high school girl suffering seriously from Chūnibyō (the age of fourteen would either act like a know-it-all adult, or thinks they have special powers no one else has. You might google it for detailed explanation) who, unfortunately, performs badly at math courses. After scoring so poorly on her maths test, she is faced with the situation that her club would be disband if her scores keeps low.
    Believe it or not, in the next exam she faces a hard problem described as follows.
    Let’s denote f(x) number of ordered pairs satisfying (a * b)|x (that is, x mod (a * b) = 0) where a and b are positive integers. Given a positive integer n, Rikka is required to solve for f(1) + f(2) + . . . + f(n).
    According to story development we know that Rikka scores slightly higher than average, meaning she must have solved this problem. So, how does she manage to do so?

    Input

    There are several test cases.
    For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 1011).
    Input is terminated by EOF.

    Output

    For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is the desired answer.

    题目大意

    求有序三元组$(a,b,c)$满足$a*b*c=n$的个数

    题目分析

    考虑以下三种做法:

    大力卷积吧!

    发现$sum_{abc=n} extbf{1}$这是一个卷积的形式,那么卷两次即可。

    时间复杂度:$O(nln n)$

    线性筛

    注意到$n$的质因数之间互不影响。那么考虑将$n$分解为$n=p_1^{a_1} imes p_2^{a_2} imes cdots imes p_k^{a_k}$的形式,于是答案就是${ m f(n)}={(a_1+1) imes (a_1+2)over{2}} imes {(a_2+1) imes (a_2+2)over{2}} imes cdots imes {(a_k+1) imes (a_k+2)over{2}}$.

    这样子做一遍线性筛就好了。

    时间复杂度:$O(n)$

    转化一下

    注意到这个顺序实际上不是必要的,也就是说完全可以算出无序的答案之后反过来考虑有序,即$abc≤n$的答案数.

    那么只需要枚举$a,b$,就可以得到$c$的范围即$[b,{left lfloor frac{n}{ab} ight floor}]$。

    此时若$a=b$,如果$c=b$会产生1种方案;$c≠b$有${left lfloor frac{n}{ab} ight floor}-b$种情况、而每一种情况会产生3种方案。这里所谓产生的方案即有序所带来的额外贡献。那么$a≠b$时同理。

    时间复杂度:$O(n^{frac{2}{3}})$

     1 #include<bits/stdc++.h>
     2 typedef long long ll;
     3 
     4 ll n,ans;
     5 int scenario;
     6 
     7 int main()
     8 {
     9     while (scanf("%lld",&n)!=EOF)
    10     {
    11         ans = 0;
    12         for (ll i=1; i*i*i<=n; i++)
    13             for (ll j=i; i*j*j<=n; j++)
    14             {
    15                 ll k = n/(i*j);
    16                 if (j > k) break;
    17                 if (i==j) ans += (k-j)*3ll+1;
    18                 else ans += (k-j)*6ll+3;
    19             }
    20         printf("Case %d: %lld
    ",++scenario,ans);
    21     }
    22     return 0;
    23 }

    END

  • 相关阅读:
    JavaScript(js)的replace问题的解决
    如何让Log4net日志文件按每月归成一个文件夹,StaticLogFileName参数的用法
    点到线的距离计算公式
    如何写一个Python万能装饰器,既可以装饰有参数的方法,也可以装饰无参数方法,或者有无返回值都可以装饰
    Python如何动态的为对象添加方法或属性,__slots__用法
    Python生成器的用法,使用生成器灵活的生成斐波那契数列
    Python函数名做参数,闭包,装饰器
    Python迭代器的用法,next()方法的调用
    property用法,使Python中的get方法和set方法使用更简单
    python中for循环删除不全的问题
  • 原文地址:https://www.cnblogs.com/antiquality/p/9879677.html
Copyright © 2011-2022 走看看