Pak Chanek plans to build a garage. He wants the garage to consist of a square and a right triangle that are arranged like the following illustration.
Define 𝑎
and 𝑏 as the lengths of two of the sides in the right triangle as shown in the illustration. An integer 𝑥 is suitable if and only if we can construct a garage with assigning positive integer values for the lengths 𝑎 and 𝑏 (𝑎<𝑏) so that the area of the square at the bottom is exactly 𝑥. As a good friend of Pak Chanek, you are asked to help him find the 𝑁
-th smallest suitable number.
Input
The only line contains a single integer 𝑁
(1≤𝑁≤109
).
Output
An integer that represents the 𝑁
-th smallest suitable number.
Example
Input
Copy
3
Output
Copy
7
Note
The 3
-rd smallest suitable number is 7. A square area of 7 can be obtained by assigning 𝑎=3 and 𝑏=4.
题目的大概意思就是寻找第n个最小的正方形面积;
通过打表很容易就能找到规律
其中注意的是1需要特判
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<bitset>
#include<cstring>
#include <unordered_set>
//#include<priority_queue>
#include<queue>
#include<deque>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define endl "\n"//交互题一定要关!!!!!!!!!
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//priority_queue<int,vector<int>,greater<int> >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef pair<long double,long double> PDD;
ll INF = 0x3f3f3f3f;
//const ll LINF=LLONG_MAX;
// int get_len(int x1,int y1,int x2,int y2)
// {
// return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
// }
const ll N = 2e5+ 10;
// const ll mod1 =998244353;
// const ll mod2 =1e9+7;
// const ll hash_num = 3e9+9;
ll n,m,ca;
ll arr[N],brr[N],crr[N],drr[N];
//ll h[N],ne[N],e[N],w[N],book[N],idx;
//ll idx;
// void add(ll a, ll b , ll c)
// {
// e[idx] = b, w[idx] = c,ne[idx] = h[a], h[a] =idx ++ ;
// }
void solve()
{
cin >> n;
ll ant= n%3;
ll cnt = 12*(n/3+1);
if(n==1)
{
cout << 3;
return;
}
if(ant==0)
{
cout << cnt/3-1<<endl;
}else if(ant==1)
{
cout << cnt/3<<endl;;
}else if(ant==2)
{
cout << cnt/3+1<<endl;
}
}
int main()
{
IOS;
ll _;
_=1;
//scanf("%lld",&_);
//cin>>_;
ca=1;
while(_--)
{
solve();
ca++;
}
return 0;
}
中间博客断了好久了,因为一些特殊的事情,一直没来的及去写,在这里立一个小的flag,每周至少5篇博客吧,写啥都行,就是记录。看到学长拿到icpc银牌也是非常羡慕。还有一年,我也要打了,加油!