LightOJ1236 Pairs Forming LCM 素因子分解

  1. 约数,倍数,质因数等都应该联想素因子分解。
  2. 要考虑哪些情况应该排除,哪些不应该排除,细节的处理。
  3. 这道题当一对数相等时不判重,而只有一对这样的数,就是(n,n)。

题目链接:http://acm.hust.edu.cn/vjudge/problem/26946

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<ctime>
#include<vector>
#include<fstream>
#include<list>
using namespace std;

#define ms(s) memset(s,0,sizeof(s))
typedef unsigned long long ULL;
typedef long long LL;

const int INF = 0x3fffffff;

const int N = 10000000;
bool primeTable[N+5];
int p[N/10],tot;
int e[N/10];
LL ans;

void make_primeTable(){
    tot = 0;
    fill(primeTable,primeTable+N,1);
    primeTable[0] = false;
    primeTable[1] = false;

    int maxed = sqrt(N);
    for(int i = 2; i <= maxed; ++i){
        if(primeTable[i] == true){
            p[tot++] = i;
            for(int j = i*i; j <= N; j += i)
                primeTable[j] = false;
        }
    }
    for(int i = maxed+1; i <= N; ++i)
        if(primeTable[i] == true)  p[tot++] = i;
}
void add_factor(LL n){
    memset(e,0,sizeof(e));
    ans = 1;
    if(n < 2)  return;
    for(int i = 0; i < tot; ++i){
        while(n%p[i] == 0){
            e[i]++;
            n /= p[i];
        }
        ans *= 2*e[i]+1;
        if(n == 1LL)  break;
    }
    if(n > 1LL){
        ans *= 3;
    }
    ans = (ans+1)/2;
}

int main()
{
//    freopen("F:\\input.txt","r",stdin);
//    freopen("F:\\output.txt","w",stdout);
//    ios::sync_with_stdio(false);
    make_primeTable();
    int t;
    LL n;
    scanf("%d",&t);
    for(int cas = 1; cas <= t; ++cas){
        scanf("%lld",&n);
        add_factor(n);
        printf("Case %d: %lld\n",cas,ans);
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值