8.3 第五场 Banzhuan
8.3 第五场 Banzhuan
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 3324 Accepted Submission(s): 664
Problem Description
Given a three-dimensional space of [1,n]×[1,n]×[1,n]. You’re required to place some 1×1×1 cubes to make this 3D space look n×n square from above, from left and from front, while the plane xOy stand for the ground and z axis describes the height.
But placing these cubes must follow some restrictions. Obviously, it must obey the gravity laws. It means, when beneath a cube is empty, the height of this cube will drop one, until its height is exactly 1 (touch the ground) or there is another cube below it.
And besides that, placing cubes has some prices. If a cube is placed at an integer coordinate (x,y,z), the price will be x×y2×z.
Now, satisfying all the requirements above, you’re required to calculate the minimum costs and the maximum costs.
Input
The first line contains an integer T(T≤15). Then T test cases follow.
For each test case, input a single integer n per line, while satisfying 1≤n≤1018.
Output
For each test case, output two lines. For the first line output the minimum costs mod 109+7. And for the second line, output the maximum costs mod 109+7.
Sample Input
1
2
Sample Output
27
60
大概题意:
求摆出边长为n
的立方体最大代价和最小代价。
思路:
最大是n
次最高层,最小是底层加上两个侧面减去一条棱。
代码:
//
// Created by Black on 2021/8/3.
//
//27是111,112,212,211,121,221,122
//x y z
//1 1 1 1
//1 1 2 2
//2 1 1 2
//2 1 2 4
//1 2 1 4
//1 2 2 8
//2 2 1 8
//2 2 2 16
// 最小 (x,y,1)
// 最大 (x,y,n)面 * n
//(x,1,z) =
//(x,y,1) =
//(x,y,n) =
// y = n * (n + 1) * (2 * n + 1) / 6
// x = n * (n + 1) / 2
// z = n * (n + 1) / 2
// _x1z = x * x
// _1yz = y * y
// _1yz = y * y
#include<iostream>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
ll Pow(ll x, ll k) {
ll ret = 1;
for (; k; k >>= 1, x = x * x % MOD)
if (k & 1)
ret = ret * x % MOD;
return ret;
}
int main() {
long long t, n;
cin >> t;
while (t--) {
cin >> n;
n %= MOD;
long long least = ((-2 + n + n * n % MOD) % MOD *
(((-6 + 2 * n % MOD) % MOD + 3 * n * n % MOD) % MOD + n * n % MOD * n % MOD) % MOD *
Pow(6, MOD - 2) % MOD +
n * (n + 1) % MOD * (2 * n + 1) % MOD * Pow(12, MOD - 2) % MOD * n % MOD * (n + 1) %
MOD + MOD) % MOD;
long long most =
n * n % MOD * (n + 1) % MOD * n % MOD * (n + 1) % MOD * (2 * n + 1) % MOD * Pow(12, MOD - 2) % MOD * n %
MOD;
cout << least << endl << most << endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效