当前位置: 首页 > news >正文

混子文章|蓝桥杯一题 -平方差

 题目考点: 平方差 ,平方差奇偶关系

 

代码

#include<bits/stdc++.h>
#define Run 0
#define endl "\n"
#define N 100005
using unl = __int128_t;
using ll = long long;
using namespace  std;
class Solution {
public: void slove() {int sum = 0;int L, R; cin >> L >> R;// 要将 x 分为奇数偶数 奇数x y 相差 1 偶数 xy 相差 2for (int i = L; i <= R; i++) {if(i % 2 != 0) sum++;else if (i % 4 == 0) sum++;}cout << sum << endl;}
};signed main() {cin.tie(0) -> ios::sync_with_stdio(0);cout.tie(0) -> ios::sync_with_stdio(0);#if Runint _;cin>>_;while(_--) Solution().slove();#elseSolution().slove();#endifreturn 0;
}

思路解析

如果 x 为奇数 y + z = x , y - z = 1

如果 x 为偶数 y + z = x / 2 y - z = 2

http://www.lryc.cn/news/303505.html

相关文章:

  • 计算机视觉基础:【矩阵】矩阵选取子集
  • 解决laravel-admin安装报错1071 Specified key was too long问题
  • 【Python---六大数据结构】
  • 一个简短的补充------对链表练习题的补充补充
  • Spring最新核心高频面试题(持续更新)
  • [计网底层小探索]:实现并部署多线程并发Tcp服务器框架(基于生产者消费者模型的线程池结构)
  • Spring Boot 笔记 020 redis集成
  • 防火墙——计算机网络
  • 用html编写的招聘简历
  • 215数组中的第K个最大元素
  • 【动态规划】【矩阵快速幂】LeetCode2851. 字符串转换
  • 【LeetCode每日一题】单调栈 402 移掉k位数字
  • 力扣 309. 买卖股票的最佳时机含冷冻期
  • 2024年刷题记录
  • 【JGit 】简述及学习资料整理
  • python数据类型-集合set
  • excel如何指定求和
  • 服务端实时推送技术之SSE(Server-Send Events)
  • 使用IntelliJ IDEA查看接口的全部实现方法
  • 阿里云幻兽帕鲁服务器操作系统类型怎么选择?
  • Codeforces Round 927 (Div. 3) LR-remainders的题解
  • HarmonyOS—@Observed装饰器和@ObjectLink嵌套类对象属性变化
  • The method toList() is undefined for the type Stream
  • vue+element (el-progress)标签 隐藏百分比(%) ,反向显示 ,自定义颜色, demo 复制粘贴拿去用
  • Android轻量级进程间通信Messenger源码分析
  • C#开发AGV地图编辑软件
  • 嵌入式学习day22 Linux
  • 不确定性问题的论文笔记
  • C语言推荐书籍
  • 基于uniapp微信小程序的汽车租赁预约系统