Factors and Factorials 

The factorial of a number N (written N!) is defined as the product of all the integers from 1 to N. It is often defined recursively as follows:

Factorials grow very rapidly--5! = 120, 10! = 3,628,800. One way of specifying such large numbers is by specifying the number of times each prime number occurs in it, thus 825 could be specified as (0 1 2 0 1) meaning no twos, 1 three, 2 fives, no sevens and 1 eleven.

Write a program that will read in a number N (  ) and write out its factorial in terms of the numbers of the primes it contains.

Input

Input will consist of a series of lines, each line containing a single integer N. The file will be terminated by a line consisting of a single 0.

Output

Output will consist of a series of blocks of lines, one block for each line of the input. Each block will start with the number N, right justified in a field of width 3, and the characters `!', space, and `='. This will be followed by a list of the number of times each prime number occurs in N!.

These should be right justified in fields of width 3 and each line (except the last of a block, which may be shorter) should contain fifteen numbers. Any lines after the first should be indented. Follow the layout of the example shown below exactly.

Sample input

5
53
0

Sample output

  5! =  3  1  1
53! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
1
#include <cstdio>
#include <cstring>
using namespace std;
bool isprime(int a)
{
int i;
for (i = 2; i*i <= a;i++)
if (a%i == 0)
return false;
return true;
}
int prime[100], count[100];
int main()
{
int n;
int i,num;
for (i = 2, num = 0; i <= 100;i++)
if (isprime(i))
{
prime[num++] = i;
} while (scanf("%d", &n) == 1 && n)
{
memset(count,0,sizeof(count));
int maxn = 0;
for (i = 2; i <= n; i++)
{
int m = i;
int j;
for (j = 0; j < num; j++)
{
while (m%prime[j] == 0)
{
m = m / prime[j];
count[j]++;
if (j>maxn)
maxn = j;
}
}
}
printf("%3d! =", n);
for (i = 0; i <= maxn; i++)
{
if (i == 15)
printf("\n ");
printf("%3d", count[i]);
} printf("\n");
}
return 0;
}

  这道题应该特别注意输出格式。

UVA 160 - Factors and Factorials的更多相关文章

  1. UVA 1575 Factors

    https://vjudge.net/problem/UVA-1575 题意: 令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式. 例 10=2*5=5*2,所以f(10)=2 ...

  2. [UVA160]Factors and Factorials 题解

    前言 这道题目本身毫无技术含量珂言,但是输出格式珂以调一年 题解 这道题让我们求\(N!\)中每个质数的个数. 一种方法是直接模拟,枚举\(N!\)中的每个元素,然后暴力查看每个数含有有多少质数. 但 ...

  3. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

  4. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  5. \r\n和\n的区别

    写Java代码的时候习惯用\r\n换行,这样可移植性比较好但是,在UVa - 160中就出现了错误,来看看是为什么吧. http://bbs.csdn.net/topics/220033879

  6. UVA 10699 Count the factors 题解

    Time limit 3000 ms OS Linux Write a program, that computes the number of different prime factors in ...

  7. uva 129 krypton factors ——yhx

     Krypton Factor  You have been employed by the organisers of a Super Krypton Factor Contest in which ...

  8. UVa 884 - Factorial Factors

    题目:输出n!中素数因数的个数. 分析:数论.这里使用欧拉筛法计算素数,在计算过程中求解就可以. 传统筛法是利用每一个素数,筛掉自己的整数倍: 欧拉筛法是利用当前计算出的全部素数,乘以当前数字筛数: ...

  9. UVa 11621 - Small Factors

    称号:发现没有比给定数量少n的.只要2,3一个因素的数字组成. 分析:数论.贪婪,分而治之. 用两个三分球,分别代表乘法2,和繁殖3队列,队列产生的数字,原来{1}. 然后.每取两个指针相应元素*2和 ...

随机推荐

  1. [Azure Devops] 使用 Azure Boards 管理工作

    1. 什么是 Azure Boards 通过 Azure Boards 网络服务,团队可以管理其软件项目.它提供了丰富的功能,包括 Scrum 和看板的本地支持.可定制的仪表板和集成报告.这些工具可以 ...

  2. 阿里二面:什么是mmap?

    平时在面试中你肯定会经常碰见的问题就是:RocketMQ为什么快?Kafka为什么快?什么是mmap? 这一类的问题都逃不过的一个点就是零拷贝,虽然还有一些其他的原因,但是今天我们的话题主要就是零拷贝 ...

  3. springboot集成swagger实战(基础版)

    1. 前言说明 本文主要介绍springboot整合swagger的全过程,从开始的swagger到Knife4j的进阶之路:Knife4j是swagger-bootstarp-ui的升级版,包括一些 ...

  4. 手机浏览器通过Scheme跳转APP,兼容各种手机浏览器

    一个比较完整的产品线,必定有APP和网站,另外还有微信公众号网页和小程序.那么有一个比较常见的需求就是在手机浏览器内打开APP,实现起来也比较简单,只要APP配置的有URLScheme即可. 但是因为 ...

  5. Unity2D项目-平台、解谜、战斗! 1.3移动组件

    各位看官老爷们,这里是RuaiRuai工作室,一个做单机游戏的兴趣作坊. 在这一篇中,我们将会自顶向下地讨论本2D游戏中主角不可或缺的一个功能--移动控制. 首先我们简单分析一下2D游戏中主角与移动相 ...

  6. vue 快速入门 系列 —— vue 的基础应用(下)

    其他章节请看: vue 快速入门 系列 vue 的基础应用(下) 上篇聚焦于基础知识的介绍:本篇聚焦于基础知识的应用. 递归组件 组件是可以在它们自己的模板中调用自身的.不过它们只能通过 name 选 ...

  7. MySQL数据库高级二:索引优化

    索引优化非常的重要 1.预热 java开发 DBA培训很少,需要经验磨练 索引优化的效果非常好 左外连接 MySQL没有全连接 7种join一定要会写 具体见武林的例子 union的字段顺序要相同 6 ...

  8. 自动化kolla-ansible部署ubuntu20.04+openstack-victoria之镜像制作debian9.6.0-17

    自动化kolla-ansible部署ubuntu20.04+openstack-victoria之镜像制作debian9.6.0-17 欢迎加QQ群:1026880196 进行交流学习   制作Ope ...

  9. @Transactional+@Autowired出现的lateinit property xx has not been initialized错误

    1 问题描述 用Kotlin编写Spring Boot,在业务层中使用@Transactional+@Autowired时出现如下错误: lateinit property dao has not b ...

  10. Nginx/Apache + acme.sh 实现https访问

    1 概述 acme.sh实现了acme协议,可以从Let's Encrypt生成免费的ssl证书用于实现https,本文介绍了常见的两种服务器Apache与Nginx上利用acme.sh配置https ...