AcWing 3418. 杨辉三角形
原题链接
简单
作者:
张智豪
,
2021-04-27 22:32:14
,
所有人可见
,
阅读 566
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2005;
ll f[N][N];
int main()
{
int n;
cin >> n;
for (int i = 1; i < N; i ++ )
for (int j = 1; j <= i; j ++ )
{
if (i == 1 && j == 1) f[i][j] = 1;
else f[i][j] = f[i - 1][j] + f[i - 1][j - 1];
if (f[i][j] > 1e9) f[i][j] = 1e10;
if (f[i][j] == n)
{
cout << i * 1ll * (i - 1) / 2 + j << endl;
return 0;
}
}
int m = sqrt(n * 2) + 1;
if (m * (m - 1) / 2 == 0) cout << m * 1ll * (m + 1) / 2 + 3 << endl;
else cout << n * 1ll * (n + 1) / 2 + 2 << endl;
return 0;
}