day4 POJ 3372 Candy Distribution

寫好程序後交上去TLE,之後對拍發現答案就是判斷是否爲2的冪。。so。。

#include"iostream"
using namespace std;
int f(int n)
{
    return((n&(n-1))==0);
}
int main()
{
    int n;
    while(cin>>n)
    {
        if(f(n)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章