1 solutions
-
0
C++ :
#include <bits/stdc++.h> using namespace std; int a[100]; bool check(int n){ memset(a,0,sizeof a); int len = 0; while (n){ a[len++] = n % 2; n /=2; } //for (int i = 0;i<len;i++) cout << a[i]; // cout << endl; for (int i = 0;i<len/2;i++){ if (a[i] != a[len-i-1]){ return false; } } return true; } int main(){ int n,ans = 0;; cin >> n; for (int i = 1;i<=n;i++){ if (check(i)) ans ++; } cout << ans; return 0; }
- 1
Information
- ID
- 131
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 6
- Accepted
- 4
- Uploaded By