题意:a[n] = ([n/1] + [n/2] + ... + [n/n]) & 1 == false,找出a数组的规律来就ok了。
1 #pragma comment(linker, "/STACK:10240000,10240000") 2 3 #include <iostream> 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstdlib> 7 #include <cstring> 8 #include <map> 9 #include <queue> 10 #include <deque> 11 #include <cmath> 12 #include <vector> 13 #include <ctime> 14 #include <cctype> 15 #include <set> 16 17 using namespace std; 18 19 #define mem0(a) memset(a, 0, sizeof(a)) 20 #define lson l, m, rt << 1 21 #define rson m + 1, r, rt << 1 | 1 22 #define define_m int m = (l + r) >> 1 23 #define rep(a, b) for (int a = 0; a < b; a++) 24 #define rrep(a, b) for (int a = (b - 1); a >= 0; a--) 25 #define all(a) (a).begin(), (a).end() 26 #define lowbit(x) ((x) & (-(x))) 27 #define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {} 28 #define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {} 29 #define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {} 30 #define pc(a) putchar(a) 31 #define ps(a) printf("%s", a) 32 #define pd(a) printf("%d", a) 33 #define sd(a) scanf("%d", &a) 34 35 typedef double db; 36 typedef long long LL; 37 typedef unsigned long long uLL; 38 typedef pair<int, int> pii; 39 typedef multiset<int> msi; 40 typedef set<int> si; 41 typedef vector<int> vi; 42 typedef map<int, int> mii; 43 44 const int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 45 const int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; 46 const int maxn = 5 * 1e4 + 7; 47 const int maxm = 1e5 + 7; 48 const int minv = 1e7 + 7; 49 const int max_val = 1e6 + 7; 50 const int MD = 1e9 +7; 51 const LL INF = 1e15; 52 const double PI = acos(-1.0); 53 const double eps = 1e-10; 54 55 template<class T> T gcd(T a, T b) { return b == 0? a : gcd(b, a % b); } 56 57 uLL a, b; 58 59 uLL g(LL n) { return n * (2 * n - 1); } 60 61 uLL f(uLL x) { 62 uLL l = 1, r = 0xFFFFFFFF; 63 while (l < r) { 64 uLL m = (l + r) >> 1; 65 if (m * m < x) l = m + 1; 66 else r = m; 67 } 68 uLL n = l, rest = x - (n - 1) * (n - 1), ans = 0; 69 if (n & 1) ans += rest; 70 ans += g(n >> 1); 71 return ans; 72 } 73 74 int main() { 75 //freopen("in.txt", "r", stdin); 76 while (cin >> a >> b) { 77 a++; b++; 78 cout << f(b) - f(a - 1) << endl; 79 } 80 return 0; 81 }
时间: 2024-10-08 00:23:22