zoukankan      html  css  js  c++  java
  • 杭电1719--Friend(找规律)

    Friend

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2131    Accepted Submission(s): 1074


    Problem Description
    Friend number are defined recursively as follows.
    (1) numbers 1 and 2 are friend number;
    (2) if a and b are friend numbers, so is ab+a+b;
    (3) only the numbers defined in (1) and (2) are friend number.
    Now your task is to judge whether an integer is a friend number.
     

     

    Input
    There are several lines in input, each line has a nunnegative integer a, 0<=a<=2^30.
     

     

    Output
    For the number a on each line of the input, if a is a friend number, output “YES!”, otherwise output “NO!”.
     

     

    Sample Input
    3
    13121
    12131
     

     

    Sample Output
    YES!
    YES!
    NO!
     

     

    Source
     

     

    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1905 2082 1073 1717 1852 
     
    friend数: n = (a + 1)(b + 1) - 1;
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 using namespace std;
     5 int main(){
     6     int n;
     7     while(~scanf("%d", &n)){
     8         if(!n){
     9             printf("NO!
    ");
    10             continue;
    11         }
    12         n += 1;
    13         while(n % 2 == 0 || n % 3 == 0){
    14             if(n % 2 == 0)
    15                 n /= 2;
    16             else
    17                 n /= 3;
    18         }
    19         if(n == 1)
    20             printf("YES!
    ");
    21         else
    22             printf("NO!
    ");
    23     }
    24     return 0;
    25 }
     
     
  • 相关阅读:
    pandas去重方法
    原生表单组件
    html表单
    html表格基本标签
    文档和网站架构
    文本格式
    【Leetcode链表】奇偶链表(328)
    【Leetcode链表】移除链表元素(203)
    【Leetcode链表】旋转链表(61)
    【Leetcode链表】反转链表 II(92)
  • 原文地址:https://www.cnblogs.com/soTired/p/4727512.html
Copyright © 2011-2022 走看看