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 aa and bb as the lengths of two of the sides in the right triangle as shown in the illustration. An integer xx is suitable if and only if we can construct a garage with assigning positive integer values for the lengths aa and bb (a<ba<b) so that the area of the square at the bottom is exactly xx. As a good friend of Pak Chanek, you are asked to help him find the NN-th smallest suitable number.
Input
The only line contains a single integer NN (1≤N≤1091≤N≤109).
Output
An integer that represents the NN-th smallest suitable number.
Example
input
Copy
3
output
Copy
7
Note
The 33-rd smallest suitable number is 77. A square area of 77 can be obtained by assigning a=3a=3 and b=4b=4.
题意:a*a+x=b*b,让你求符合条件的第n个x是多少
思路:x=b*b-a*a=(a+b)*(b-a)
那么我们对a,b两个数进行讨论
如果两个数同奇偶的话:(a+b)是偶数,(b-a)也是偶数
那么(a+b)*(b-a)就是4的倍数(除了4,因为a+b和b-a不可能同时等于2)
如果两个数不同奇偶的话:(a+b)是奇数,(a-b)是奇数
那么(a+b)*(b-a)也是奇数(除了1,因为不可能同时等于1)
那么我们就列出来这些数
3 5 7 8 9 11 12 13 15 16...
发现了规律:
对于前四个数单独输出,后面的数每隔三个是4的倍数
/*
.----------------. .----------------. .----------------. .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. |
| | ________ | || | _________ | || | ____ ____ | || | ____ | |
| | |_ ___ `. | || | |_ ___ | | || ||_ \ / _|| || | .' `. | |
| | | | `. \ | || | | |_ \_| | || | | \/ | | || | / .--. \ | |
| | | | | | | || | | _| _ | || | | |\ /| | | || | | | | | | |
| | _| |___.' / | || | _| |___/ | | || | _| |_\/_| |_ | || | \ `--' / | |
| | |________.' | || | |_________| | || ||_____||_____|| || | `.____.' | |
| | | || | | || | | || | | |
| '--------------' || '--------------' || '--------------' || '--------------' |
'----------------' '----------------' '----------------' '----------------'
*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<cmath>
#include<stack>
#define int long long
#define lowbit(x) x&(-x)
#define PI 3.1415926535
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int gcd(int a,int b) {
return b? gcd(b,a%b):a;
}
/*
int dx[8]={-2,-2,-1,1,2,2,-1,1};
int dy[8]={-1,1,2,2,1,-1,-2,-2};
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int dx[8]={-1,1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
*/
//int e[N],ne[N],h[N],idx,w[N];
/*void add(int a,int b,int c){
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
*/
const int N=2e5+10;
int m,p,n;
void sove(){
cin>>n;
if(n==1){
cout<<3<<endl;
return ;
}
if(n==2){
cout<<5<<endl;
return ;
}
if(n==3){
cout<<7<<endl;
return ;
}
if(n==4){
cout<<8<<endl;
return ;
}
int op=(n-4)/3;
if((n-4)%3){
op++;
}
op+=2;
//cout<<"op=="<<op<<endl;
if((n-4)%3==0){
cout<<op*4<<endl;
}else if((n-4)%3==1){
cout<<op*4-3<<endl;
}else{
cout<<op*4-1<<endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie() ,cout.tie() ;
int t=1;
// cin>>t;
while(t--){
sove();
}
return 0;
}