zoukankan      html  css  js  c++  java
  • HDU1405:The Last Practice

    Problem Description
    Tomorrow is contest day, Are you all ready?
    We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.

    Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.
    what does this problem describe?
    Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.
     
    Input
    Input file contains multiple test case, each case consists of a positive integer n(1<n<65536), one per line. a negative terminates the input, and it should not to be processed.
     
    Output
    For each test case you should output its factor as sample output (prime factor must come forth ascending ), there is a blank line between outputs.
     
    Sample Input
    60 12 -1
     
    Sample Output
    Case 1. 2 2 3 1 5 1 Case 2. 2 2 3 1
    Hint
    60=2^2*3^1*5^1
     

    //目前为止碰到的最坑的格式了

    最后有空格

    有空格!!!!!!

    #include <stdio.h>
    #include <string.h>
    
    int prime[1000000];
    
    void sushu(void)
    {
        memset(prime,1,sizeof(prime));
        int i,j;
        for(i = 2; i<=500000; i++)
        {
            if(prime[i])
            {
                for(j = i+i; j<1000000; j+=i)
                {
                    prime[j] = 0;
                }
            }
        }
    }
    
    int main()
    {
        int n,cas = 1,k = 0;
        sushu();
        while(~scanf("%d",&n) && n>=0)
        {
            int cnt = 0,i;
            if(k)
                printf("\n");
            printf("Case %d.\n",cas++);
            k++;
            if(prime[n])
            {
                printf("%d 1 \n",n);
                continue;
            }
            else if(n%2 == 0)
            {
                while(n%2 == 0)
                {
                    n/=2;
                    cnt++;
                }
                printf("2 %d ",cnt);
                for(i = 3; i<=n; i+=2)
                {
                    cnt = 0;
                    if(prime[i])
                    {
                        while(n%i == 0)
                        {
                            n/=i;
                            cnt++;
                        }
                        if(cnt)
                            printf("%d %d ",i,cnt);
                    }
                }
                printf("\n");
            }
            else
            {
                for(i = 3; i<=n; i+=2)
                {
                    cnt = 0;
                    if(prime[i] && n%i == 0)
                    {
                        while(n%i == 0)
                        {
                            n/=i;
                            cnt++;
                        }
                        if(cnt)
                        {
                            printf("%d %d ",i,cnt);
                        }
                    }
                }
                printf("\n");
            }
        }
    
        return 0;
    }
    


     


     

  • 相关阅读:
    luogu P5473 [NOI2019]I 君的探险 交互 随机 二分 分治 整体二分
    218. The Skyline Problem
    315. Count of Smaller Numbers After Self
    493. Reverse Pairs
    307. Range Sum Query
    1409. Queries on a Permutation With Key
    如果redis没有设置expire,他是否默认永不过期?
    同步调用和异步调用
    缓存穿透、缓存击穿、缓存雪崩概念及解决方案
    Python实现发送邮件---转载至https://www.cnblogs.com/liuqingzheng/articles/10072695.html
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2995110.html
Copyright © 2011-2022 走看看