zoukankan      html  css  js  c++  java
  • 洛谷——P1348 Couple number

    https://www.luogu.org/problemnew/show/P1348

    题目描述

    任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple number。你的工作就是判断一个数N是不是Couple number。

    输入输出格式

    输入格式:

    仅一行,两个长整型范围内的整数n1和n2,之间用1个空格隔开。

    输出格式:

    输出在n1到n2范围内有多少个Couple number。

    注意:包括n1和n2两个数,且n1<n2,n2 - n1 <= 10 000 000。

    输入输出样例

    输入样例#1: 复制
    1 10
    
    输出样例#1: 复制
    7


    打表找规律
     1 #include <cstdio>
     2 
     3 #define LL long long
     4 inline void read(LL &x)
     5 {
     6     x=0; register char ch=getchar(); register bool _=0;
     7     for(; ch>'9'||ch<'0'; ch=getchar()) if(ch=='-') _=1;
     8     for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0';
     9     x=_ ?((~x)+1) :x;
    10 }
    11 LL n1,n2,ans;
    12 
    13 #define Abs(x) (x>0?x:((~x)+1))
    14 
    15 int main()
    16 {
    17     read(n1),read(n2);
    18     for(LL i=n1; i<=n2; ++i)
    19         if(Abs(i)%4!=2) ans++;
    20     printf("%lld
    ",ans);
    21     return 0;
    22 }
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    常用的文件查看命令
    Linux常用快捷按键
    寒冬储粮
    创建型模式:抽象工厂
    创建型模式:工厂方法
    创建型模式:单例模式
    开闭原则
    迪米特法则
    接口隔离原则
    依赖倒置原则
  • 原文地址:https://www.cnblogs.com/Shy-key/p/7846461.html
Copyright © 2011-2022 走看看