【平方差 / C】

题目

思路

  • 打表找规律
    • 枚举小区间
    • 对于判断要妥协,我这里选取100内的x, y
cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
bool st[120];
int main()
{
    for(int i = 1; i <= 100; i++)
    {
        for(int x = 0; x <= 100; x ++)
        {
            for(int y = 0; y <= 100; y++)
            {
                if(!st[i])
                    if(i == x*x - y*y) cout << i << endl, st[i] = true;
            }
        }
    }
    return 0;
}

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
int k4(int n)
{
    return n/4;
}
int odd(int n)
{
    return (n+1)/2;
}
int main()
{
    int l, r;
    cin >> l >> r;
    
    int sum = 0;
    sum += odd(r) - odd(l-1) + k4(r) - k4(l-1);
    cout << sum;
    return 0;
}
相关推荐
远瞻。1 小时前
【论文阅读】人脸修复(face restoration ) 不同先验代表算法整理2
论文阅读·算法
先做个垃圾出来………4 小时前
哈夫曼树(Huffman Tree)
数据结构·算法
phoenix@Capricornus6 小时前
反向传播算法——矩阵形式递推公式——ReLU传递函数
算法·机器学习·矩阵
Inverse1626 小时前
C语言_动态内存管理
c语言·数据结构·算法
数据与人工智能律师6 小时前
虚拟主播肖像权保护,数字时代的法律博弈
大数据·网络·人工智能·算法·区块链
wuqingshun3141597 小时前
蓝桥杯 16. 外卖店优先级
c++·算法·职场和发展·蓝桥杯·深度优先
YouQian7728 小时前
2025春训第十九场
算法
CodeJourney.8 小时前
基于MATLAB的生物量数据拟合模型研究
人工智能·爬虫·算法·matlab·信息可视化
Epiphany.5568 小时前
素数筛(欧拉筛算法)
c++·算法·图论
爱吃涮毛肚的肥肥(暂时吃不了版)8 小时前
项目班——0510——JSON网络封装
c++·算法·json