当前位置: 移动技术网 > IT编程>开发语言>C/C++ > HDU6298 Maximum Multiple (多校第一场1001)

HDU6298 Maximum Multiple (多校第一场1001)

2018年09月03日  | 移动技术网IT编程  | 我要评论

火焰纹章if,比思上不去,股市动态分析

maximum multiple

time limit: 4000/2000 ms (java/others)    memory limit: 32768/32768 k (java/others)
total submission(s): 3241    accepted submission(s): 1344


problem description
given an integer n, chiaki would like to find three positive integers x, y and z such that: n=x+y+z, xn, yn, zn 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|n,  y|n,   z|n (整除关系),输出xyz的最大值,若不存在,输出-1
 
设 n/x = r     n/y = s      n/z = t  ,    r  <=  s  <=  t
 
所以1/r + 1/s + 1/t = 1
 
所以r <= 3
 
当r=3    s,t = (3,3)
当r=2    s,t = (4, 4) , (3, 6) 
 
所以三种情况
n/3   n/3   n/3
n/2   n/4   n/4
n/2   n/3   n/6  (没有第一种大,舍去)
 
所以就判是否能 整除3 或 4
 
 
 
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define fo freopen("in.txt", "r", stdin)
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a, b, sizeof(a))
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007;
const int inf = 0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head
int _, n;
int main() {
    for(scanf("%d", &_);_;_--) {
        scanf("%d", &n);
        if(n%3 == 0) printf("%lld\n", 1ll * n * n * n / 27);
        else if(n%4 == 0) printf("%lld\n", 1ll * n * n * n / 32);
        else puts("-1");
    }
}

 

 
 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网