#include <bits/stdc++.h> using namespace std; int f[50] ={0,1}, pod[50]; map <int, int> ktory; //liczba, numer vector<int> liczby; int main() { ios_base::sync_with_stdio(0); int i, j, n = 0, k, z = 0; ktory[0] = 0; ktory[1] = 1; for(i = 2; i < 48; i++) { f[i] = f[i-1] + f[i- 2]; ktory[f[i]] = i; } //for(i = 1; i < 48; i++) cout << i <<" "<<f[i] << endl; cin >> k; i = 45; while (k > 0 && i > 0){ if(f[i] <= k) { k = k - f[i]; pod[i] = 1; n += i +1; liczby.push_back(f[i]); } i--; } cout << n << endl; z = 2; for(j = 0; j < liczby.size();j++){ int koniec = ktory[liczby[j]]; if( j == liczby.size() - 1) cout << z <<" " << -1 <<endl; else cout << z <<" " << z + koniec <<endl; for(i = 1; i < koniec - 1; i++) { cout << z + 1 <<" " << z + 2 << endl; z++; } cout <<z + 1 <<" "<< -1 <<endl; z++; if( j != liczby.size() - 1) cout <<n <<" " << -1 << endl; z = z + 2; } cout <<-1 <<" "<< -1 << endl; 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 | #include <bits/stdc++.h> using namespace std; int f[50] ={0,1}, pod[50]; map <int, int> ktory; //liczba, numer vector<int> liczby; int main() { ios_base::sync_with_stdio(0); int i, j, n = 0, k, z = 0; ktory[0] = 0; ktory[1] = 1; for(i = 2; i < 48; i++) { f[i] = f[i-1] + f[i- 2]; ktory[f[i]] = i; } //for(i = 1; i < 48; i++) cout << i <<" "<<f[i] << endl; cin >> k; i = 45; while (k > 0 && i > 0){ if(f[i] <= k) { k = k - f[i]; pod[i] = 1; n += i +1; liczby.push_back(f[i]); } i--; } cout << n << endl; z = 2; for(j = 0; j < liczby.size();j++){ int koniec = ktory[liczby[j]]; if( j == liczby.size() - 1) cout << z <<" " << -1 <<endl; else cout << z <<" " << z + koniec <<endl; for(i = 1; i < koniec - 1; i++) { cout << z + 1 <<" " << z + 2 << endl; z++; } cout <<z + 1 <<" "<< -1 <<endl; z++; if( j != liczby.size() - 1) cout <<n <<" " << -1 << endl; z = z + 2; } cout <<-1 <<" "<< -1 << endl; return 0; } |