#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define int long long
using namespace std;
stack<int> s;
int k, n=100, tab[109][2], fib[100], ile;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin>>k;
fib[1]=1;
for(int i=2; i<50; i++)
fib[i]=fib[i-1]+fib[i-2];
int liczba=k;
while(liczba>0){
int indeks=0;
while(fib[indeks+1]<=liczba)
indeks++;
liczba-=fib[indeks];
if(!ile)
s.push(indeks-2);
else
s.push(indeks-1);
ile++;
//cout<<indeks<<" "<<fib[indeks]<<"\n";
}
//cout<<liczba<<"\n";
int poz=1, wyraz=0;
while(!s.empty()){
//cout<<s.top()<<"\n";
if(wyraz==s.top()){
//cout<<"jestem na pozycji "<<poz<<"\n";
if(ile!=1){
tab[poz-1][1]+=2;
tab[poz][1]=poz+4;
tab[poz+1][1]=n;
}
wyraz++;
poz+=3;
s.pop();
ile--;
}
else{
tab[poz][1]=poz+2;
poz++;
wyraz++;
}
}
for(int i=1; i<n; i++)
tab[i][0]=i+1;
cout<<n<<"\n";
for(int i=1; i<n; i++){
if(!tab[i][0])
cout<<"-1 ";
else
cout<<tab[i][0]<<" ";
if(!tab[i][1])
cout<<"-1\n";
else
cout<<tab[i][1]<<"\n";
}
cout<<"-1 -1\n";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include<bits/stdc++.h> #define mp make_pair #define pb push_back #define int long long using namespace std; stack<int> s; int k, n=100, tab[109][2], fib[100], ile; int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin>>k; fib[1]=1; for(int i=2; i<50; i++) fib[i]=fib[i-1]+fib[i-2]; int liczba=k; while(liczba>0){ int indeks=0; while(fib[indeks+1]<=liczba) indeks++; liczba-=fib[indeks]; if(!ile) s.push(indeks-2); else s.push(indeks-1); ile++; //cout<<indeks<<" "<<fib[indeks]<<"\n"; } //cout<<liczba<<"\n"; int poz=1, wyraz=0; while(!s.empty()){ //cout<<s.top()<<"\n"; if(wyraz==s.top()){ //cout<<"jestem na pozycji "<<poz<<"\n"; if(ile!=1){ tab[poz-1][1]+=2; tab[poz][1]=poz+4; tab[poz+1][1]=n; } wyraz++; poz+=3; s.pop(); ile--; } else{ tab[poz][1]=poz+2; poz++; wyraz++; } } for(int i=1; i<n; i++) tab[i][0]=i+1; cout<<n<<"\n"; for(int i=1; i<n; i++){ if(!tab[i][0]) cout<<"-1 "; else cout<<tab[i][0]<<" "; if(!tab[i][1]) cout<<"-1\n"; else cout<<tab[i][1]<<"\n"; } cout<<"-1 -1\n"; return 0; } |
English