数学--数论-- HDU6298 Maximum Multiple 打表找规律
生活随笔
收集整理的這篇文章主要介紹了
数学--数论-- HDU6298 Maximum Multiple 打表找规律
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y+zn=x+y+z, x∣nx∣n, y∣ny∣n, z∣nz∣n and xyzxyz is maximum.
Input
There are multiple test cases. The first line of input contains an integer TT (1≤T≤1061≤T≤106), indicating the number of test cases. For each test case: The first line contains an integer nn (1≤n≤1061≤n≤106).Output
For each test case, output an integer denoting the maximum xyzxyz. If there no such integers, output ?1?1 instead.Sample Input
3 1 2 3Sample Output
-1 -1 1只有因子中有4或者有3才能被拆成 X+Y+Z=N,然后打了表驗證。
最后wa了好幾次,是因為int和int計算之后還是int就算賦值給long long .
打表代碼
AC
#include <bits/stdc++.h> using namespace std; int main() {int T;long long n,x,y,z;long long sum;scanf("%d", &T);while (T--){scanf("%lld", &n);if ((n % 3) == 0){x = y = z = n / 3;sum = x * y * z;if (x + y + z == n)printf("%lld\n", sum);elseputs("-1");}else if ((n % 4) == 0){x = y = n / 4, z = n / 2;sum = x * y * z;if (x + y + z == n)printf("%lld\n", sum);elseputs("-1");}elseputs("-1");} }總結
以上是生活随笔為你收集整理的数学--数论-- HDU6298 Maximum Multiple 打表找规律的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows10设备怎么使用wifi
- 下一篇: ubuntu16.04配置本地镜像源_修