結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー どらら
提出日時 2016-05-14 01:41:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 1,225 bytes
コンパイル時間 855 ms
コンパイル使用メモリ 80,780 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 18:08:42
合計ジャッジ時間 2,295 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;


ll findmin(ll x){
  ll d, q;
  while(x>=4 && x%2==0){ return 2; x/=2;}
  d = 3; q = x/d;
  while(q>=d){
    if(x%d==0){ return d; x=q; }else{ d+=2; }
    q=x/d;
  }
  return x;
}

int main(){
  ios::sync_with_stdio(false);

  ll L, H;
  cin >> L >> H;

  ll ret = -1, ret_val = -1;
  for(ll j=(ll)(sqrt(H))+1; j>=2; j--){
    if(ret_val != -1 && j<ret) break;
    for(ll i=(H/j)+1; i>=j-1; i--){
      if(L > j*i) break;
      if(j*i > H) continue;

      ll res = findmin(j*i);
      if(res != j*i && res >= ret){
        if(res == ret){
          if(ret_val < j*i) ret_val = j*i;
        }else{
          ret = res;
          ret_val = j*i;
        }
      }
    }
  }
  cout << ret_val << endl;

  return 0;
}
0