結果

問題 No.1006 Share an Integer
ユーザー amaridekinaiamaridekinai
提出日時 2020-03-06 23:02:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,948 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 173,060 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-22 10:18:49
合計ジャッジ時間 2,840 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,376 KB
testcase_01 AC 15 ms
5,504 KB
testcase_02 AC 15 ms
5,632 KB
testcase_03 WA -
testcase_04 AC 15 ms
5,504 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 15 ms
5,632 KB
testcase_09 AC 16 ms
5,632 KB
testcase_10 AC 15 ms
5,760 KB
testcase_11 AC 21 ms
5,632 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long 

const int MAX_N = 2e6+10;

const int inf = 2e9;

bool arr[MAX_N];
int division[MAX_N];

set<int> se;

void eratosthenes(){
  
  for(int i = 0; i < MAX_N; i++){ arr[i] = true;}
  
  arr[0] = false; arr[1] = false;
  
  for(int i = 2; i < MAX_N; i++){  //素因数列挙
    if(arr[i] ){ 
     for(int j = 2; i*j < MAX_N; j++){
       
       arr[i*j] = false;
     }
    }
  }
  
  for(int i = 0; i < (int)sqrt(MAX_N); i++){ 
    if( arr[i] ){ 
      se.insert(i);
    }
  }
  
  return ;
}

signed main(void){
  
  int N; cin >> N;
  
  if( N % 2 == 0 ){ cout << 0 << endl; return 0;} 
  
  set<pair<int,int>> ans;
  eratosthenes();
  
 
  division[1] = 1;
  
  int left  = max(N/2 - (int)sqrt(N) - 100,1LL);
  int right = min(N/2 + (int)sqrt(N) + 100,N  );
  
  
  for(int i = left; i <= right; i++){ 
    // iの約数の個数を計算しておく
    // N/2の√N周りらへんを計算しておけば十分そう(予想)
    
    
    int res = i;
    
    int s = 1LL;
    
    if( arr[res] ){ division[i] = 2; continue;} 
    // p と 1
      
      for(auto d : se){ 
        
        if(res % d == 0 ){ 
          
          int cnt = 1LL;
          
          while( res % d == 0  ){ 
            res /= d;
            cnt++;
          }
          
          s *= cnt;
          if( res == 1 ){ break;} //for-脱出
        }// if res%d
      }//for-d
    
     division[i] = s;

  }
  
  
  int rem = inf;
  
  for(int A = left; A <= right; A++){ 
    
    int B = N-A;
    
    if( !(A&&B) ){ continue;}
    
    int FA = A-division[A];
    int FB = B-division[B];
    
    if( rem > abs(FA-FB) ){ 
      rem = abs(FA-FB); 
      ans.clear();
      ans.insert({A,B});
    }
    else if( rem == abs(FA-FB) ){ 
      ans.insert({A,B});
    }
    
  }
  
  for(auto ne : ans ){ cout << ne.first << " " << ne.second << endl;}

    return 0;
  
                     
}
0