• 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
  • 相关阅读:
    洛谷P1043数字游戏
    luogu P1330 封锁阳光大学
    luoguP1242 新汉诺塔
    luogu P1892 [BOI2003]团伙
    luogu P3375 【模板】KMP字符串匹配
    luoguP1440 求m区间内的最小值
    luoguP2700 逐个击破
    luoguP2814 家谱
    luogu P1962 斐波那契数列
    P3379 【模板】最近公共祖先(LCA)
  • 原文地址:https://www.cnblogs.com/acboyty/p/9653009.html
Copyright © 2020-2023  润新知