现在的位置: 首页 > 综合 > 正文

hdu 1781 Friend

2018年04月29日 ⁄ 综合 ⁄ 共 505字 ⁄ 字号 评论关闭

题意是,1,2是Friend number,

其他的Friend number必须由两个Friend number   a,b由ab+a+b组成。。

ab+a+b=(a+1)(b+1)-1,

而a,b也是Friend number,就这样推下去最终会得到friend number=((1+1)^x)*((1+2)^y)-1;

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int s[10005];
int main()
{
    int a;
    while(~scanf("%d",&a))
    {
        if(a==0)
        {
            printf("NO!\n");
            continue;
        }
        a=a+1;
        while(a%2==0)
            a=a/2;
        while(a%3==0)
            a=a/3;
        if (a == 1)
            printf("YES!\n");
        else
            printf("NO!\n");
    }
    return 0;
}

抱歉!评论已关闭.