2019-06-09 22:42:04 C++

C++

Copy Copied! Full
#include <bits/stdc++.h> using namespace std; void printb(unsigned int v) { unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1); do putchar(mask & v ? '1' : '0'); while (mask >>= 1); } int main(void){ int L; cin >> L; vector<int> v; for(int i=1;i<=L;i++){ int ans = 0; for(int a=0;a<=i;a++){ for(int b=0;a+b<=i;b++){ int c = a^b; if((a+b)==c){ ans++; } } } v.push_back(ans); } for(int i=1;i<=L;i++){ printb(i); printf("のとき%d\n",v[i-1]); } }
RECOMMEND