結果

問題 No.9005 実行時間/使用メモリテスト(テスト用)
ユーザー maimai
提出日時 2016-07-13 13:05:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 3,000 ms
コード長 1,176 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 75,476 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 16:23:43
合計ジャッジ時間 1,064 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:34:25: warning: 'maxpf' may be used uninitialized [-Wmaybe-uninitialized]
   34 |         if (0<=maxi && n<maxpf)
      |                        ~^~~~~~
main.cpp:24:11: note: 'maxpf' was declared here
   24 |     llint maxpf,maxi=-1;
      |           ^~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long int llint;

// 最小の素因数を求める。u>=3
llint pfactor(llint u){
    if (u%2==0) return 2ll;
    for (llint i=3ll;i*i<=u;i+=2ll)
        if (u%i==0) return i;
    return u;
}

llint dataset[]={0,100000000000000,1000000000000000,10000000000000000,10000000000000,1000000000000000000};

int main(){
    llint n,i,t;
    llint l,h,hq;
    llint maxpf,maxi=-1;
       
    cin>>i;
    l=3;
    h=dataset[i];
    hq=floor(sqrt(h));
    
    for (n=hq;2ll<=n;n--){
        if (h/n*n<l || pfactor(n)!=n)
            continue;
        if (0<=maxi && n<maxpf)
            break;
        for (i=h/n;n<=i;i--){
            if (i*n<l)
                break;
            if ((maxi<0 || n!=maxpf) && pfactor(i)==i){
                //cout<<(i*n)<<endl;
                cout<<0<<endl;
                exit(0);
            }
            t=pfactor(i*n);
            if (maxi<0 || (maxpf<t || (maxpf==t && maxi<i*n) )){
                maxi=i*n; maxpf=t;
            }
        }
    }
    
    //cout<<maxi<<endl;
    cout<<0<<endl;
    return 0;
}
0