完全平方數 (打表)

https://ac.nowcoder.com/acm/contest/5203/C

打表例題。

#include <iostream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <string>
#include <cstdio>
#include <set>
#include <cstdio>
#include <fstream>
#include <deque>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <iomanip>
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
const int mod = 1e9 + 7;
const double esp = 1e-5;
const double PI = 3.141592653589793238462643383279;
using namespace std;
const int N = 1e7 + 5;
const int maxn = 1 << 20;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; while (b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
/*void chafen(int l, int r, int k) {//差分函數
    p[l] += k;
    p[r + 1] -= k;
}*/
/*************************************************************/
ll s[N];
int main() {
    ll t = 0;
    for (int i = 0; i * i <= 1000000000; i++)
        s[++t] = i * i;
    int n;
    cin >> n;
    while (n--) {
        ll l, r;
        cin >> l >> r;
        int pos1 = upper_bound(s + 1, s + 1 + t, r) - s;
        int pos2 = lower_bound(s + 1, s + 1 + t, l) - s;
        int ans = pos1 - pos2;
        cout << ans << endl;
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章