码迷,mamicode.com
首页 > 其他好文 > 详细

UVA11461- Square Numbers

时间:2014-09-15 17:48:29      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   io   os   ar   for   sp   代码   

题目链接


题意:求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;
}


UVA11461- Square Numbers

标签:style   http   color   io   os   ar   for   sp   代码   

原文地址:http://blog.csdn.net/u011345461/article/details/39294997

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!