zoukankan      html  css  js  c++  java
  • HDU6814 Tetrahedron(几何/数论/逆元)

    Generate three integers (a), (b), and (c) in ([1,n]) with equal probability independently, and use them as the three right-angle side length of a right-angled tetrahedron. Find the expectation of the reciprocal square of the distance from the right-angle apex to the slope (Euclidean distance).

    For each test case, output a line containing the answer mod (998244353).

     ![img](https://vj.z180.cn/bc0539328995156faa5623ceb3e4ea0c?v=1596532892)   
    

    Input

    In the first line, you should read an integer (T) denoting the number of test cases.

    In every test case, the only line will include an integer (n).

    It is guaranteed that (T) is no larger than (2 imes 10^6) and (n) is no larger than (6 imes 10^6).

    Output

    For each test case, output the only line containing just one integer denoting the answer mod (998244353).

    Sample Input

    3
    1
    2
    3
    

    Sample Output

    3
    124780546
    194103070
    

    题意是从1~n等概率任选3个数,求以这三个数为直角边构成的直角三棱锥中直角顶点到斜平面的距离平方的倒数的期望。

    由高中数学可得有公式(frac{1}{OH^2}=frac{1}{a^2}+frac{1}{b^2}+frac{1}{c^2}),这个可以设出来三条边然后根据海伦公式推。那么最终要求的期望E就为(E(frac{1}{OH^2})=3 imes E(frac{1}{a^2})=3 imes frac{1}{n^3} imesSigma^n_{i=1}Sigma^{n^2}_{j=1}frac{1}{i^2}=frac{3}{n} imes Sigma^{n}_{i=1}frac{1}{i^2})

    然后预处理出1~6e6的(frac{1}{i^2})的前缀和,查询的时候直接输出即可。但这里还有取模操作,分数取模用到费马小定理,(frac{a}{b}\%p=a imes b^{p-2}\%p),用快速幂搞一下就好了。

    重点中的重点:(i imes i)后也要取模!WA了15发就是没注意....

    #include <bits/stdc++.h>
    #define mod 998244353
    typedef long long ll;
    using namespace std;
    long long ans[6000005]; 
    long long ksm(long long x,long long y){
        long long a=1;
        while(y){
            if(y&1) a=a*x%mod;
            y>>=1;
            x=x*x%mod;
        }
        return a;
    }
    int main()
    {
    	//freopen("A.in","r",stdin);
    	//freopen("my.out","w",stdout);
    	int t;
    	cin >> t;
    	ans[1] = 1;
    
    	for(long long i = 2; i <= 6000005; i++)
    	{
    		ans[i] = ksm(i * i % mod, mod-2) % mod;
    		ans[i] = (ans[i - 1] % mod + ans[i] % mod) % mod;
    	}
    	while(t--)
    	{
    		long long n;
    		scanf("%lld", &n);
    		printf("%lld
    ", ans[n] * 3 * ksm(n , mod-2) % mod);
    	}
    	return 0;
    }  
    
  • 相关阅读:
    php RabbitMQ使用
    phalcon: 开启模板缓存和缓存路径
    phalcon:整合官方多模块功能,方便多表查询
    mysql: 模糊查询 feild like keyword or feild like keyword , concat(feild1,feild2,feild3) like keyword
    php的http数据传输get/post...
    java大数字操作:BigInteger,BigDecimal(浮点型)
    DecimalFormat数据格式函数
    MySQL比like语句更高效的写法locate position instr find_in_set
    mysql中使用instr替换like
    mysql中的多行查询结果合并成一个
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13440820.html
Copyright © 2011-2022 走看看