problem link:- Stern-Brocot Tree
submit link:- Submit
code ref:- c++ language, bfs-tree
#include<bits/stdc++.h>
using namespace std;
Solution:
#include<bits/stdc++.h> using namespace std; int main()
{
#include<bits/stdc++.h>
using namespace std;
int a[10001],b[10001];
int main()
{
SOLIUTION LINK::http://paste.ubuntu.com/24305142/
#include<bits/stdc++.h> using namespace std; int mx = 20000007; char mark[20000007]; void sieve() { mark[0] = mark[1] = 1; // 1 means not prime for(int i = 4; i<mx; i+=2) mark[i] = 1; for(int i = 3; i*i<mx; i+=2) if(mark[i]==0) // i is a prime number for(int j = i*i; j<mx; j+=i+i) mark[j] = 1; } int main() { vector<int>a; vector<int>c; vector<int>d; long long int n; sieve(); for(int l=0; l<=20000000; l++) { if(mark[l]==0) { a.push_back(l); } } for(int r=1;r<a.size();r++) { if((a[r])-a[r-1]==2) { c.push_back(a[r-1]); // change d.push_back(a[r]); // change } } while(cin>>n) { cout<<'('<<c[n-1]<<", "<<d[n-1]<<')'<<endl; } return 0; }