UvaOJ 10110 – Light, more light

來源:互聯網
上載者:User

題目

看了n遍終於看懂了,大意是,走廊上有1~n盞燈,人在走廊上走n個來回,每次走人都會按燈的開關。按開關的策略是這樣的,第 i 次走,人只按燈編號能被 i 整除的燈的開關。問你最後走完了,第n盞燈的狀態是開還是關。燈的初始狀態都是關的。

簡單數論。僅當n為完全平方數時,n的狀態是開。

注意題目中說 n是  less then or equals 2^32-1 ,int 放不下(-2^31
(-2147483648) 到2^31-1 (2147483647)),要用long long
或 unsigned int,不然wa。

代碼: 

#include<iostream>#include<cmath>#include<cstdio>using namespace std;typedef long long int64;int64 n;int64 isqur(int64 x){    int64 t = (int64)(sqrt((double)x)+0.5);    if(t*t == x) return 1;    else return 0;}int main(){    while(cin>>n && n)    {        printf(isqur(n)? "yes\n": "no\n");    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.