UVA11461- Square Numbers

题目链接

题意:求a到b之间的平方数的数量

思路:暴力,水题

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

const int MAXN = 100005;

int vis[MAXN];

int judge(int n) {
    double a = sqrt((double)n);
    int b = (int)a;
    if (a - b < 1e-6)
        return true;
    return false;
}

int main() {
    int a, b;
    while (scanf("%d%d", &a, &b) && (a || b)) {
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        for (int i = a; i <= b; i++) {
            if (judge(i)) {
                cnt++;
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}

时间: 2024-10-13 08:52:30

UVA11461- Square Numbers的相关文章

UVA 11461 Square Numbers解题报告

Discription A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive). In

633. Sum of Square Numbers

Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3Output: False 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

[leetcode-633-Sum of Square Numbers]

Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False 思路: 类似于二分查找. 从0 和sqrt(n)两端分别查找. bool

LeetCode Sum of Square Numbers

原题链接在这里:https://leetcode.com/problems/sum-of-square-numbers/description/ 题目: Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 *

[LeetCode] Sum of Square Numbers 平方数之和

Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False s

LeetCode 633. Sum of Square Numbers平方数之和 (C++)

题目: Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False 分析: 给定一个非负整数c ,你要判断是否存在两个整数a和b,使

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

HDU1398 Square Coins

Description People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 28

UVA - 11461-Square Numbers

11461 - Square Numbers Time limit: 1.000 seconds A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to ?nd out how many square numbers are t

HDOJ Square Coins 1398【母函数】

Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9761    Accepted Submission(s): 6692 Problem Description People in Silverland use square coins. Not only they have square shapes but