P9231 [蓝桥杯 2023 省 A] 平方差

因式分解之后发现,满足条件的x要么是奇数,要么是4的倍数

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#define R(x) x = read()
#define For(i, j, n) for(int i = j ; i <= n ; ++i)
using namespace std;

inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
       x = x * 10 + ch - '0';
       ch = getchar();
    }
     return x * f;
}

int l, r;

int f(int n)
{
    return (n + 1)/2 + n/4;
}

int main()
{
    R(l);R(r);
    printf("%d\n", f(r) - f(l - 1));
    return 0;
}

 

posted @ 2024-04-08 11:04  Gold_stein  阅读(7)  评论(0编辑  收藏  举报