zoukankan      html  css  js  c++  java
  • UVA 10892

    Problem F LCM Cardinality Input: Standard Input

    Output: Standard Output

    Time Limit: 2 Seconds

    A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called the LCM cardinality of that number N. In this problem your job is to find out the LCM cardinality of a number.

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    Input

    The input file contains at most 101 lines of inputs. Each line contains an integer N (0<N<=2*109). Input is terminated by a line containing a single zero. This line should not be processed.

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    Output

    For each line of input except the last one produce one line of output. This line contains two integers N and C. Here N is the input number and C is its cardinality. These two numbers are separated by a single space.

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    Sample Input                             Output for Sample Input

    2
    12
    24
    101101291
    0

    2  2

    12  8

    24  11

    101101291  5

    #include <iostream>
    #include <stdio.h>
    #include <queue>
    #include <stdio.h>
    #include <string.h>
    #include <vector>
    #include <queue>
    #include <set>
    #include <algorithm>
    #include <map>
    #include <stack>
    #include <math.h>
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    using namespace std ;
    typedef long long LL ;
    const int M=45000 ;
    bool isprime[M+10] ;
    int prime[M] ,id;
    void make_prime(){
        id=0 ;
        memset(isprime,0,sizeof(isprime)) ;
        for(int i=2;i<=M;i++){
            if(!isprime[i])
                prime[++id]=i ;
            for(int j=1;j<=id&&prime[j]*i<=M;j++){
                isprime[i*prime[j]]=1 ;
                if(i%prime[j]==0)
                   break ;
            }
        }
    }
    LL gao(LL x){
       LL sum ;
       LL ans=1 ;
       for(int i=1;i<=id&&prime[i]*prime[i]<=x;i++){
           if(x%prime[i]==0){
                sum=0 ;
                while(x%prime[i]==0){
                    sum++ ;
                    x/=prime[i] ;
                }
                ans=ans*(sum+sum+1) ;
           }
           if(x==1)
               break  ;
       }
       if(x!=1)
           ans*=3 ;
       return (ans+1)>>1 ;
    }
    int main(){
       LL x ;
       make_prime() ;
       while(cin>>x&&x){
           cout<<x<<" "<<gao(x)<<endl ;
       }
       return 0 ;
    }

  • 相关阅读:
    移动端链接、点击事件、输入框去除背景高亮
    Quartz.Net与MVC结合定时任务
    Win10上使用SVN遇到的一些问题
    Win7上的ASP.NET MVC3项目在Win10上运行的一个坑
    《SQL必知必会》学习笔记(二)
    《SQL必知必会》学习笔记(一)
    数据库知识总结(表结构操作)
    搭建三层架构(ASP.NET MVC+EF)
    python线程中的全局变量与局部变量
    ADO.NET Entity Framework学习笔录(一)
  • 原文地址:https://www.cnblogs.com/liyangtianmen/p/3381372.html
Copyright © 2011-2022 走看看