結果

問題 No.375 立方体のN等分 (1)
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-06-04 23:26:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,020 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 96,388 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 01:23:45
合計ジャッジ時間 1,747 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 7 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>
 
using namespace std;

typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

vector<ll> p_decom(ll m){
  vector<ll> v;
  while(m % 2 == 0){
    v.push_back(2);
    m /= 2;
  }
  for(ll i = 3; i * i <= m; i += 2){
    while(m % i == 0){
      v.push_back(i);
      m /= i;
    }
  }
  if(m > 1){
    v.push_back(m);
  }
  sort(all(v));
  return v;
}

ll n;
vector<ll> v;
vector<ll> v1;

ll f1(ll a,ll p){
	ll p1 = 1;
	rep(i,0,v1.sz){
		if(((p>>i)&1)==1){
			p1 *= v1[i];
		}
	}
	return p1+a/p1;
}

ll f(ll p){
	ll p1 = 1;
	rep(i,0,v.sz){
		if(((p>>i)&1)==1){
			p1 *= v[i];
		}
	}
	ll a = n/p1;
	if(a==1){
		return p1-1;
	}
	v1 = p_decom(a);
	long long left = 1;
	long long right = 1<<(v1.sz)-1;

	while(left != right){
		long long d = (right - left) / 3;
		long long l = f1(a,left + d);
		long long r = f1(a,right - d);
		if(d == 0){
			if(l > r)left++;
			else right--;
		}
		else{
			if(l > r)left = left + d;
			else right = right - d;
		}
	}
	return (p1-1)+f1(a,left)-2;
}

int main(){
	cin>>n;
	v = p_decom(n);
	long long left = 1;
	long long right = 1<<(v.sz)-1;

	while(left != right){
		long long d = (right - left) / 3;
		long long l = f(left + d);
		long long r = f(right - d);
		if(d == 0){
			if(l > r)left++;
			else right--;
		}
		else{
			if(l > r)left = left + d;
			else right = right - d;
		}
	}
	cout << f(left) << " " << n-1 << endl;
	return 0;
}
0