zoukankan      html  css  js  c++  java
  • 2021“MINIEYE杯”中国大学生算法设计超级联赛(2)1001. I love cube(思维)

    Problem Description

    Give you a cube with a side length of n-1. Find the number of equilateral triangles with three points on the cube point. Each side must be parallel to a certain surface of Oxy, Oxz, Oyz. Now you need to count how many such triangles there are.Each point can only be on the boundary or inner point of the cube, and the three coordinates x, y, and z of each point must be integers.

    Input

    The first line contains an integer T(T<=1e5) . Then T test cases follow.

    Each test case contains a single Integer n(0<=n<=1e18).

    If n=0, output 0

    Output

    For each case, print an integer, which is the answer modulo 109+7

    Sample Input

    2
    1
    2
    

    Sample Output

    0
    8
    

    观察发现三个点所有坐标都是整数的三角形只可能是第二个样例的那八种情况,即类似(0, 0, 0), (1, 0, 1), (0, 1, 1)。证明的话正三角形一条边平行于棱的情况很容易发现是不成立的,其他情况emmm

    这样就只需要知道边长为n - 1的立方体包含多少边长为1,2...n-1的立方体,再将答案乘以8即可。

    (Sigma_{i = 1}^{n-1}8 imes i^3 =2(n(n-1))^2)。n-1必须要先模一下模数!

    #include <bits/stdc++.h>
    #define mod 1000000007
    #define int __int128
    using namespace std;
    inline __int128 read()
    {
       int X=0,w=0; char ch=0;
       while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
       while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
       return w?-X:X;
    }
    void print(__int128 x)
    {
        if(x<0)
        {
            putchar('-');
            x=-x;
        }
        if(x>9)print(x/10);
        putchar(x%10+'0');
    }
    signed main() {
    	signed t;
    	cin >> t;
    	while(t--) {
    		int n;
    		n = read();
    		//边平行于棱的肯定没有
    		if(n == 0 || n == 1) {
    			cout << 0 << endl;
    			continue;
    		}
    		n--;
    		//cout << (1 + n) * n / 2 * 8 << endl;
    		n %= mod;
    		print((1 + n) * n % mod * (1 + n) % mod * n % mod * 2 % mod);
    		cout << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    30 分钟快速入门 Docker 教程
    python functools.wraps
    计算机科学中最重要的32个算法
    JDBC的作用及重要接口
    SSO单点登录--支持C-S和B-S
    谈谈Sql server 的1433端口
    屏蔽:粘贴到KindEditor里,IE下弹出框报”对象不支持moveToElementText属性或方法“错误的提示
    markdown
    ddd
    python进阶学习(一)--多线程编程
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/15047783.html
Copyright © 2011-2022 走看看