暴力 hihoCoder 1178 计数

题目传送门

 1 /*
 2     暴力:这题真是醉了,直接暴力竟然就可以了!复杂度不会分析,不敢写暴力程序。。
 3             枚举x,在不重复的情况下+ans,超过范围直接break
 4 */
 5 #include <cstdio>
 6 #include <algorithm>
 7 #include <cstring>
 8 #include <cmath>
 9 using namespace std;
10 
11 typedef long long ll;
12 const int MAXN = 1e7 + 10;
13 const int INF = 0x3f3f3f3f;
14 bool vis[MAXN];
15 
16 int main(void)        //hihoCoder 1178 计数
17 {
18 //    freopen ("B.in", "r", stdin);
19 
20     ll n, L, R;
21     while (scanf ("%lld", &n) == 1)
22     {
23         if (n == 0)    break;
24         scanf ("%lld%lld", &L, &R);
25         memset (vis, false, sizeof (vis));
26 
27         int ans = 0;
28         for (ll i=1; i<=5e7; ++i)
29         {
30             ll tmp = i ^ (n * i);
31             if (tmp >= L && tmp <= R)    {if (!vis[tmp]) {vis[tmp] = true;    ans++;}}
32         }
33 
34         printf ("%d
", ans);
35     }
36 
37     return 0;
38 }
编译人生,运行世界!
原文地址:https://www.cnblogs.com/Running-Time/p/4576501.html