返回顶部

牛客编程巅峰赛S1第5场 - 青铜&白银 B.完全平方数的尾巴 (暴力)

  • 题意:有一个数\(x\),判断其是否能有某个完全平方数$mod$1000得到.

  • 题解:直接写个for判断一下就好了,因为对1000取模,所以枚举到1000即可.

  • 代码:

    class Solution {
    public:
        /**
         *
         * @param x int整型
         * @return bool布尔型
         */
        bool solve(int x) {
            // write code here
            const int mod=1000;
            for(int i=1;i<=1000;++i){
                if(i*i%mod==x){
                    return true;
                }
            }
            return false;
        }
    };
    
posted @ 2020-07-24 12:08  _Kolibri  阅读(199)  评论(0)    收藏  举报