LightOJ 1035 Intelligent Factorial Factorization 因子分解水题

题目:http://www.lightoj.com/volume_showproblem.php?problem=1023

题意:给一个数n,把n!写成因子相乘的形式,* a (b)意味a是n!的因子,b是n!中a的个数

思路:数据范围很小,直接暴力分解因子即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const int N = 110;
int cas;
int main()
{
    int t, n;
    scanf("%d", &t);
    while(t--)
    {
        int num[N];
        memset(num, 0, sizeof num);
        scanf("%d", &n);
        for(int i = 2; i <= n; i++)
        {
            int m = i, j = 2;
            while(m != 1)
            {
                while(m % j == 0) num[j]++, m /= j;
                j++;
            }
        }
        printf("Case %d: %d = ", ++cas, n);
        bool flag = false;
        for(int i = 2; i <= n; i++)
            if(num[i])
            {
                if(!flag) printf("%d (%d)", i, num[i]), flag = true;
                else printf(" * %d (%d)", i, num[i]);
            }
        printf("\n");
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值