4 条题解

  • 2
    @ 2023-2-1 17:54:26

    本题思路:贪心

    一个性质

    当是两两互质的质数时,他们的乘积等于最大最小公倍数

    #include <iostream>
    #include <stack>
    #include <cmath>
    #include <vector>
    #include <string.h>
    #include <queue>
    #include <stdio.h>
    #include <iomanip>
    #include <cstdio>
    #include <algorithm>
    #define int long long
    using namespace std;
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    signed main()
    {
    	int n;
    	cin >> n;
    	if(n % 2 == 1)
    	{
    		cout << n * (n - 1) * (n - 2);
    	}	
    	else if(n % 3 == 0)
    	{
    		cout << (n - 1) * (n - 2) * (n - 3);
    	}
    	else
    	{
    		cout << n * (n - 1) * (n - 3);
    	}
    	return 0;
    }
    
  • 1
    @ 2025-9-18 13:57:45
    #include <stdio.h>
    long long n;
    int main()
    {
    	scanf("%lld\n", &n);
    	printf("%lld\n", n & 1 ? n * (n - 1) * (n - 2) : !(n % 3) ? (n - 1) * (n - 2) * (n - 3) : n * (n - 1) * (n - 3));
    	return 0;
    }
    
    • -1
      @ 2024-5-19 21:43:42

      思路:枚举(暴力)

      #include <bits/stdc++.h>
      using namespace std;
      long long zs[1000001];
      void zsb(){
      	bool l;
      	for(int i = 2,k = 1 ; i <= 1000000 ; i++){
      		l = false;
      		for(int j = 2 ; j <= sqrt(i) ; j++){
      			if(i % j == 0){
      				l = false;
      				break;
      			}
      		}
      		if(!l){
      			zs[k] = i;
      			k++;
      		}
      	}
      }
      bool zdgys(int a,int b){
      	int i = 1;
      	while(zs[i] < b){
      		if(a % zs[i] == 0 && b % zs[i] == 0) return false;
      		i++;
      	}
      	return true;
      }
      long long a,b,maxn = -100000000001;
      int main(){
      	zsb();
      	cin >> a;
      	b = a - 2;
      	while(!(zdgys(a,b) && zdgys(a - 1,b))) b--;
      	maxn = max(b * (a - 1) * a,maxn);
      	a--;
      	b = a - 2;
      	while(!(zdgys(a,b) && zdgys(a - 1,b))) b--;
      	maxn = max(b * (a - 1) * a,maxn);
      	cout << maxn << endl;
      	return 0;
      }
      
      • -2
        @ 2024-11-9 18:11:20

        利用性质 两两互质,乘积为他们的最大最小公倍数

        思路很难!!

        #include<bits/stdc++.h>
        using namespace std;
        int n;
        int main(){
        	cin>>n;
        	if(n%2==1){
        		cout<<n*(n-1)*(n-2);
        	}	
        	else if(n%3==0){
        		cout<<(n-1)*(n-2)*(n-3);
        	}
        	else{
        		cout<<n*(n-1)*(n-3);
        	}    
        	return 0;
        } 
        
        • 1

        信息

        ID
        980
        时间
        1000ms
        内存
        128MiB
        难度
        6
        标签
        递交数
        338
        已通过
        97
        上传者