#50353: 不要暴力解(1 <= n < 2^63)


kenny980721.tu@gmail.com (有事直接私)

學校 : 國立中興大學附屬高級中學
編號 : 290039
來源 : [220.134.29.87]
最後登入時間 :
2025-09-13 17:26:11

 

TLE程式碼 (一個一個找因數比大小):

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    long long n;
    cin >> n;
    int Max=0,Max_index=0;
    for(long long i=1;i<=n;i++){
        int N=sqrt(i);
        int total=0;
        for(int j=1;j<=N;j++){
            if(i%j==0){
                if(i/j!=j)total+=2;
                else total+=1;
            }
        }
        if(total>Max){
            Max=total;
            Max_index=i;
        }
    }
    cout << Max_index << " " << Max;
}