• HDU 6298


    Problem Description
    Given an integer n, Chiaki would like to find three positive integers xy and z such that: n=x+y+zxnynzn and xyz is maximum.
     
    Input
    There are multiple test cases. The first line of input contains an integer T (1T106), indicating the number of test cases. For each test case:
    The first line contains an integer n (1n106).
     
    Output
    For each test case, output an integer denoting the maximum xyz. If there no such integers, output 1 instead.
     
    Sample Input
    3 1 2 3
     
    Sample Output
    -1 -1 1
     
     
    题目意思:给你n个数,要你找出X,Y,Z, X+Y+Z = n,并且 X,Y, Z 是 n 的一个因子(我当时不认识“ | ”这个符号,想了半天), 输出X * Y * Z 的最大值。
    题解:X + Y + Z = n 两边同时除以n, 得到 x/n + y/n + z/n = 1,分别设为 a,b,c; 1/3 + 1/3 +1/3 = 1    1/2 + 1/3+ 1/6  1/2 + 1/4 + 1/4 = 1。另外套for循环 打表发现 必须是3 和 4的倍数才符合题意。 所以就是 1 3 两种情况满足题意。
     
     1 #include <iostream>
     2 using namespace std;
     3 typedef long long ll;
     4 
     5 int main(){
     6     int T;
     7     scanf("%d",&T);
     8     while(T--){
     9         ll n;
    10         ll max = 0;
    11         scanf("%lld",&n);
    12         if(n%3 == 0){
    13             max = n*n*n/27;cout<<max<<endl;
    14         }
    15         
    16         else if(n%4 == 0){
    17             max = n*n*n/32;cout<<max<<endl;
    18         }
    19         
    20         else 
    21         cout<<"-1"<<endl;
    22         
    23     } 
    24     return 0;
    25 }
  • 相关阅读:
    linux tmux基本操作
    AJAX json集合传入Controller后台
    python 数据读取
    appium
    接口测试设计思路
    python 常用模块
    接口测试程序部分
    测试用例设计思路
    mock_待续
    网站收藏
  • 原文地址:https://www.cnblogs.com/stul/p/9884946.html
Copyright © 2020-2023  润新知