zoukankan      html  css  js  c++  java
  • hdu 6298 Maximum Multiple (简单数论)

    Maximum Multiple

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 3313    Accepted Submission(s): 1382


    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满足:n=x+y+z, xn, yn, zn,并使xyz最大。求最大的xyz,若不存在,则输出-1。

    简单数论题。

    1可以分解成这样几个形式:

    1=1/3+1/3+1/3  1=1/2+1/4+1/4  1=1/2+1/3+1/6

    而他们对应的乘积分别是1/27 > 1/32 > 1/36。

    所以应当优先考虑n被3整除的情况,然后是被2整除,最后是被6整除。由于被3整除包含被6整除,故只需考虑前两种情况即可。注意输出用long long。

    #include<cstdio>
    
    using namespace std;
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            long long n;
            scanf("%lld",&n);
            if(n%3==0)
            {
                printf("%lld
    ",(n/3)*(n/3)*(n/3));
            }
            else if(n%4==0)
            {
                printf("%lld
    ",(n/2)*(n/4)*(n/4));
            }
            else
            {
                printf("-1
    ");
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    pytest+allure生成测试报告
    pytest之fixture使用详解
    pytest框架介绍
    使用records库操作SQL并且查询MySQL数据库
    python模块之codecs
    项目总结
    第二阶段团队绩效评分
    软件发布2.0
    “随手记”开发记录day20
    “随手记”开发记录day19
  • 原文地址:https://www.cnblogs.com/acboyty/p/9653009.html
Copyright © 2011-2022 走看看