Submission #8150200


Source Code Expand

Copy
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	ll N; cin >> N;
	ll ans = N - 1;
	FOR(i, 1, 1000010) {
		if (N % i == 0) {
			ans = min(ans, i + N / i - 2);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Submission Info

Submission Time
Task C - Walk on Multiplication Table
User Geothermal
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1522 Byte
Status
Exec Time 12 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 300 / 300 hand_01, hand_02, hand_03, hand_04, hand_05, hand_06, hand_07, hand_08, large_01, large_02, large_03, large_04, large_05, large_06, large_07, large_08, prime_01, prime_02, prime_03, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, sample_01, sample_02, sample_03, small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, square_01, square_02, square_03
Case Name Status Exec Time Memory
hand_01 12 ms 256 KB
hand_02 12 ms 256 KB
hand_03 12 ms 256 KB
hand_04 12 ms 256 KB
hand_05 12 ms 256 KB
hand_06 12 ms 256 KB
hand_07 12 ms 256 KB
hand_08 12 ms 256 KB
large_01 12 ms 256 KB
large_02 12 ms 256 KB
large_03 12 ms 256 KB
large_04 12 ms 256 KB
large_05 12 ms 256 KB
large_06 12 ms 256 KB
large_07 12 ms 256 KB
large_08 12 ms 256 KB
prime_01 12 ms 256 KB
prime_02 12 ms 256 KB
prime_03 12 ms 256 KB
random_01 12 ms 256 KB
random_02 12 ms 256 KB
random_03 12 ms 256 KB
random_04 12 ms 256 KB
random_05 12 ms 256 KB
random_06 12 ms 256 KB
random_07 12 ms 256 KB
random_08 12 ms 256 KB
sample_01 12 ms 256 KB
sample_02 12 ms 256 KB
sample_03 12 ms 256 KB
small_01 12 ms 256 KB
small_02 12 ms 256 KB
small_03 12 ms 256 KB
small_04 12 ms 256 KB
small_05 12 ms 256 KB
small_06 12 ms 256 KB
small_07 12 ms 256 KB
small_08 12 ms 256 KB
square_01 12 ms 256 KB
square_02 12 ms 256 KB
square_03 12 ms 256 KB