zoukankan      html  css  js  c++  java
  • 平方末尾

    能够表示为某个整数的平方的数字称为“平方数”
    比如,25,64
    虽然无法立即说出某个数是平方数,但经常可以断定某个数不是平方数。
    因为平方数的末位只可能是:[0, 1, 4, 5, 6, 9] 这6个数字中的某个。
    所以,4325435332必然不是平方数。

    如果给你一个2位或2位以上的数字,你能根据末位的两位来断定它不是平方数吗?

    请计算一下,一个2位以上的平方数的最后两位有多少种可能性?

    注意:需要提交的是一个整数,表示2位以上的平方数最后两位的不同情况数。
    不要填写任何多余内容(比如,说明解释文字等)

     答案:

    这道题很有意思,显然不能无休止的测试下去,平方数的最后两位,其实只跟末尾两位有关系,所以只需要遍历100以内的情况即可。

    代码:

    #include <iostream>
    #include <cstdio>
    #include <set>
    using namespace std;
    bool vis[100];
    int c;
    int main() {
        for(int i = 0;i < 100;i ++) {
            if(!vis[i * i % 100]) c ++;
            vis[i * i % 100] = true;
        }
        printf("%d
    ",c);
        for(int i = 0;i < 100;i ++) {
            if(vis[i]) printf("%d ",i);
        }
    }
  • 相关阅读:
    [leetcode]Palindrome Partitioning II
    [wikioi]传纸条
    [leetcode]Palindrome Partitioning
    [leetcode]Convert Sorted List to Binary Search Tree
    [topcoder]ActivateGame
    [topcoder]NinePuzzle
    [topcoder]BestRoads
    [topcoder]IncreasingSubsequences
    [leetcode]Surrounded Regions
    CF 432B :Football Kit
  • 原文地址:https://www.cnblogs.com/8023spz/p/10731649.html
Copyright © 2011-2022 走看看