# 埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛 F 1 + 2 = 3?(找规律)

(表示按位异或运算)
Input:

Output:

Sample Input:
4
1
2
3
10
Sample Output:
1
2
4
18

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 100;
const double eps = 1e-5;
const double e = 2.718281828459;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 1; i < maxn; ++i) {
if ((i ^ (2 * i)) == (3 * i)) {
cout << i << endl;
}
}
return 0;
}


1
2
4
5
8
9
10
16
17
18
20
21
32
33
34
36
37
40
41
42
64
65
66
68
69
72
73
74
80
81
82
84
85


#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 502;
const double eps = 1e-5;
const double e = 2.718281828459;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 1; i < maxn; ++i) {
if ((i ^ (2 * i)) == (3 * i)) {
cout << bitset<sizeof(i) * 2>(i) << endl;
}
}
return 0;
}


00000001
00000010
00000100
00000101
00001000
00001001
00001010
00010000
00010001
00010010
00010100
00010101
00100000
00100001
00100010
00100100
00100101
00101000
00101001
00101010
01000000
01000001
01000010
01000100
01000101
01001000
01001001
01001010
01010000
01010001
01010010
01010100
01010101


1 1
2 1
3 2
4 3
5 5
6 8
7 13

AC代码:

#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 502;
const double eps = 1e-5;
const double e = 2.718281828459;

ll Fib[60];
ll Fib_sum[60];

void init() {
Fib[1] = 1;
Fib_sum[1] = 1;
Fib[2] = 1;
Fib_sum[2] = 2;
for (int i = 3; i < 60; ++i) {
Fib[i] = Fib[i - 1] + Fib[i - 2];
Fib_sum[i] = Fib[i];
Fib_sum[i] += Fib_sum[i - 1];
}
}

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
init();
int t;
cin >> t;
while (t--) {
ll n, ans = 0;
cin >> n;
bool flag = 0;
while (n) {
if (flag) {
if (n == 1) {
break;
}
else {
n--;
}
}
int book = 1;
for (int i = 1; i < 60; ++i) {
if (Fib_sum[i] >= n) {
book = i;
break;
}
}
if (book > 2) {
n -= Fib_sum[book - 1];
}
else {
n -= Fib_sum[book];
}
for (int i = 1; i < book; ++i) {
}
flag = 1;
}
cout << ans << endl;
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120