1 条题解

  • 0
    @ 2025-5-6 20:17:36

    手搓,或者打表,都可以发现这道题的答案。

    题意是求 xyzxyz 在满足 x+y+z=nx+y+z=n 并且 xn,  yn,  znx\mid n,\;y\mid n,\;z\mid n 的情况下的最大值;

    t=nxt=\frac{n}{x}s=nys=\frac{n}{y}r=nzr=\frac{n}{z},由上面的条件可得 $$\frac1t + \frac1s + \frac1r = 1$$ ,因为 t,s,rt,s,r 为整数,而该不定方程的整数解只有如下三组,其中 xyzxyz 如下表所示:

    tt ss rr xyzxyz
    33 $$3$$ 33 n327\dfrac{n^3}{27}
    22 44 $$4$$ n332\dfrac{n^3}{32}
    $$2$$ 33 66 n336\dfrac{n^3}{36}

    显然如果满足第三种则一定满足第一种,因为是求最大值,所以第三种可以舍弃。如果三种都不满足,就输出1-1

    注意:如果同时满足多种情况,要优先判断并输出xyzxyz大的情况。

    时间复杂度:O(T×1)O(T \times 1)

    #include <iostream>
    #define endl '\n'
    using namespace std;
    using LL = long long;
    
    void solve(){
    	int n;
    	cin >> n;
    	if(n % 3 == 0){
    		cout << (LL)n * n * n / 27 << endl;
    	}
    	else if(n % 4 == 0){
    		cout << (LL)n * n * n / 32 << endl;
    	}
    	else cout << -1 << endl;
    }
    
    int main(){
    	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    	int T;
    	cin >> T;
    	while(T--){
    		solve();
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    2270
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    94
    已通过
    20
    上传者