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;
    }
    
  • 相关阅读:
    JVM深入理解(四)-内存模型【上】
    JVM深入理解(三)-加载与字节码执行
    JVM深入理解(二)-结构与内存管理
    初级正则表达式
    光弧,高亮
    substr,subString,split,slice,replace的区别
    SpringBoot配置SSLUnable to start ServletWebServerApplicationContext due to multiple ServletWebServerFa
    79:Python开发-sqlmapapi&Tamper&Pocsuite
    76:Python开发-内外网收集Socket&子域名&DNS
    77:Python开发-批量Fofa&POC验证&SRC提取
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/15047783.html
Copyright © 2011-2022 走看看