日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数学--数论-- HDU6298 Maximum Multiple 打表找规律

發(fā)布時間:2023/12/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数学--数论-- HDU6298 Maximum Multiple 打表找规律 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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 3

Sample Output

-1 -1 1

只有因子中有4或者有3才能被拆成 X+Y+Z=N,然后打了表驗證。
最后wa了好幾次,是因為int和int計算之后還是int就算賦值給long long .
打表代碼

#include <bits/stdc++.h> using namespace std; int main() {int T;scanf("%d", &T);while (T--){int n;for (int n = 1; n <= 100; n++){int maxt = -1;int a, b, c;for (int x = 1; x <= n; x++){for (int y = 1; y <= n - x; y++){int z = n - x - y;if (z && n % x == 0 && n % y == 0 && n % z == 0){if (maxt < x * y * z){a = x;b = y;c = z;}maxt = max(maxt, x * y * z);}}}printf("%d:%5d %d %d %d\n", n, maxt, a, b, c);if (n % 12 == 0)printf("\n");}}return 0; }

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 打表找规律的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。