zoukankan      html  css  js  c++  java
  • hdu 逆袭指数

    Problem Description
      这依然是关于高富帅小明曾经的故事——

      尽管身处逆境,但小明一直没有放弃努力,除了搬砖,小明还研究过东方的八卦以及西方的星座,一直试图在命理上找到自己能够逆袭的依据。

      当这些都失败以后,小明转向了数学研究,希望从中得到一些信息。一天,小明在研究《BestCoder逆袭的数理基础》这本书时,发现了宝贵的信息,其中写道:
      每个人都存在一个逆袭指数,对于这个逆袭指数,可能存在连续的因子,如果这个连续因子足够长的话,那么这个人逆袭的概率就很大!

      小明已知自己的逆袭指数,请告诉小明他最长的连续因子,以让他来判断他自己是否能够逆袭。
     
    Input
    输入包含多组测试数据。
    每组数据占一行,包含一个整数N,表示小明的逆袭指数,N小于2^31。
     
    Output
    对于每组数据,请输出2行:
    第一行输出最长的因子个数;
    第二行输出最小的因子序列,具体请参考样例。

    特别说明:由于小明十分讨厌单身,所以1不算因子。
     
    Sample Input
    630 12
     
    Sample Output
    3 5*6*7 2 2*3
     
    Hint
    630 = 3*5*6*7
     
    题解:直接搜索就行
     
    代码:
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <ctype.h>
     7 #include <iomanip>
     8 #include <queue>
     9 #include <stdlib.h>
    10 using namespace std;
    11 
    12 int a[10010],b[10010];
    13 int i,j,k,Max;
    14 
    15 void DFS(int n,int i,int k)
    16 {
    17     if(n%i==0 && n!=1){
    18         b[k]=i;
    19         DFS(n/i,i+1,k+1);
    20     }
    21     if(Max < k){
    22         Max=k;
    23         for(j=0;j < Max;j++){
    24             a[j]=b[j];
    25         }
    26     }
    27 }
    28 
    29 int main()
    30 {
    31     int n;
    32     while(~scanf("%d",&n)){
    33         Max=0;
    34         for(i=2;i*i<=n;i++){
    35             DFS(n,i,0);
    36         }
    37         if(Max==0){
    38             Max=1;
    39             a[0]=n;
    40         }
    41         printf("%d
    ",Max);
    42         printf("%d",a[0]);
    43         for(i=1;i < Max;i++)
    44             printf("*%d",a[i]);
    45         printf("
    ");
    46     }
    47 }
    View Code
  • 相关阅读:
    sbt设置
    scala高级内容(二)
    scala高级内容(一) Case Class
    xubuntu手记
    ScalaTour 2.函数
    ScalaTour-1.基础
    springboot对jsp模板引擎的支持
    springboot对Thymeleaf模板引擎的支持
    SpringBoot接收参数的七种方式
    idea快捷代码提示和修改
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/5007664.html
Copyright © 2011-2022 走看看