阶乘和 大整数

///大整数阶乘的和
#include<bits/stdc++.h>
using namespace std;
int main()
{int n;while(cin>>n){int a[2000]= {1},b[2000]= {0}; //存放结果的数组a。int c; //b用于存放每位存放的结果。int r=0; //r用来表示进位的数。int h=1,hb=1;  //h用来表示运算过程中 结果a 的最高位在哪。for (int i=1; i<=n; i++){for (int j=0; j<h; j++){c= a[j]*i+r; //两数相乘 。a[j]=c%10; //求该位的真实数据 。r=c/10; //求进位
            }while(r) //上面j的循环结束后,r表示最高位有无进位。
            {a[h++]=r%10; //如果有,最高位应再进一,并计算最高位上的余数r/=10; //计算最高位进一后,是否还需要进位。
            }int len=max(hb,h);for(int k=0; k<len; k++){b[k]=a[k]+b[k];if(b[k]>9){b[k]-=10;b[k+1]++;}}}for(int g=max(hb,h)-1;g>=0;g--)cout<<b[g];cout<<endl;}return 0;
}

 

转载于:https://www.cnblogs.com/tp25959/p/10274237.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278454.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何添加引文标_如何在Google文档中查找和添加引文

如何添加引文标When writing papers, you need to generate a detailed and accurate list of all the sources you’ve cited in your paper. With Google Docs, you can easily find and then add citations to all of your research papers. 撰写论文时&#xff0c;您需要生…

mongo ttl索引

db.log_events.find() # 查找log_events里的所有数据db.log_events.createIndex( { "LogDT": 1 }, { expireAfterSeconds: 3600 } ) #设置log_events里的TTL过期索引清理时间为3600秒db.runComman…

Linux Centos下SQL Server 2017安装和配置

Linux Centos下SQL Server 2017安装和配置 原文:Linux Centos下SQL Server 2017安装和配置我们知道在Linux下安装服务有很多方式&#xff0c;最为简单的也就是yum安装&#xff0c;但是很多服务通过yum是无法安装的&#xff0c;如果想使用yum安装&#xff0c;需要指定yum安装仓库…

如何在Linux上使用端口敲门(以及为什么不应该这样做)

Photographee.eu/ShutterstockPhotographee.eu/ShutterstockPort knocking is a way to secure a server by closing firewall ports—even those you know will be used. Those ports are opened on demand if—and only if—the connection request provides the secret knoc…

小到年货大到产业,刘村长的扶贫模式有点厉害!

河北省阜平县平石头村的村民&#xff0c;今年春节再也不用头疼买什么年货&#xff0c;去哪买年货的问题了&#xff0c;因为他们的“村长”刘强东&#xff0c;给每户人家都送来了年货大礼包&#xff01;大礼包里不仅有牛奶、果汁、毛衣、长裤、波司登羽绒服、枕头、毛巾、炊大皇…

java - 匿名类

匿名内部类 概念&#xff1a;即内部类的简化写法 前提&#xff1a;存在一个类&#xff08;可以是具体类也可以是抽象类&#xff09;或接口 格式&#xff1a;new 类名或接口名{重写的方法} 本质&#xff1a;创建的是继承了类或实现了接口的子类匿名对 象。 匿名类总是final&…

leetcode 342. Power of Four

没想出来不用循环的。记录下。 如果是2的次方&#xff0c;必有num & (nums - 1) bool isPowerOfFour(int num) {if (num < 1) return false;if (num & (num - 1)) return false; // 排除不是2的倍数if (num & 0x55555555) return true; // 排除不是4的倍数&am…

克隆ubuntu硬盘_使用Ubuntu Live CD克隆硬盘

克隆ubuntu硬盘Whether you’re setting up multiple computers or doing a full backup, cloning hard drives is a common maintenance task. Don’t bother burning a new boot CD or paying for new software – you can do it easily with your Ubuntu Live CD. 无论是设置…

页面缓存处理的几种方法

html只要加在头部就可以了. <HEAD> <META HTTP-EQUIV"Pragma" CONTENT"no-cache"> <META HTTP-EQUIV"Cache-Control" CONTENT"no-cache"> <META HTTP-EQUIV"Expires" CONTENT"0"> </H…

Nginx的Mainline version、Stable version、Legacy version的版本区别

Nginx官网提供了三个类型的版本Mainline version&#xff1a;Mainline 是 Nginx 目前主力在做的版本&#xff0c;可以说是开发版Stable version&#xff1a;最新稳定版&#xff0c;生产环境上建议使用的版本Legacy versions&#xff1a;遗留的老版本的稳定版 nginx下载地址&…

从Boxee的Amie Street访问音乐

One of our favorite sites for discovering new music is Amie Street. Today we take a look at the Amie Street app for Boxee that allows you to access your favorite tunes from the Boxee interface. 我们最喜欢的发现新音乐的网站之一是Amie Street。 今天&#xff0…

redis学习目录

redis学习目录 redis安装 说明 python中使用 centos7安装redis redis.conf配置信息详解 redis主从同步 redis持久化 RDB与AOF redis不重启,切换到RDB备份到AOF备份 redis哨兵功能 redis-cluster(集群) 转载于:https://www.cnblogs.com/yuncong/p/10293624.html

如何在SpringBoot项目中使用拦截器

相比springmvc&#xff0c;springboot中拦截器不需要在xml中配置&#xff0c;只需定义拦截器类 implements HandlerInterceptor 和拦截器拦截路径的配置类extends WebMvcConfigurerAdapter 1.SessionInterceptor package com.example.demo;import org.springframework.web.serv…

如何在Word,Excel和PowerPoint 2010中裁剪图片

When you add pictures to your Office documents you might need to crop them to remove unwanted areas, or isolate a specific part. Today we’ll take a look at how to crop images in Office 2010. 将图片添加到Office文档时&#xff0c;可能需要裁剪它们以删除不需要…

Python 调度算法 死锁 静动态链接 分页分段

1 select poll epoll的区别基本上select有3个缺点: 连接数受限查找配对速度慢数据由内核拷贝到用户态poll改善了第一个缺点 epoll改了三个缺点. (1&#xff09;select&#xff0c;poll实现需要自己不断轮询所有fd集合&#xff0c;直到设备就绪&#xff0c;期间可能要睡眠和唤醒…

在Windows 7 Media Center中创建音乐播放列表

One of the new features in Windows 7 Media Center is the ability to easily create music playlists without using Media Player. Today we’ll take a closer look at how to create them directly in Media Center. Windows 7 Media Center的新功能之一是无需使用Media …

(转)WebSphere的web工程中怎么获取数据源

原文&#xff1a;http://aguu125.iteye.com/blog/1694313 https://blog.csdn.net/bigtree_3721/article/details/44900325-------JNDI之java:comp/env was配置数据源和tomcat是不同的。tomcat只需要配置tomcat 的service.xml或者content.xml&#xff0c;然后 WEB程序就不需要配…

阿里数据库内核月报:2017年04月

摘要&#xff1a;阿里数据库内核月报&#xff1a;2017年04月# 01 MySQL 源码分析 MySQL 半同步复制数据一致性分析# 02 MYSQL 新特性 MySQL 8.0对Parser所做的改进# 03 MySQL 引擎介绍 Sphinx源码剖析&#xff08;二&#xff09;# 04 PgSQL 特性分析 checkpoint机制浅析…

SQL Server2008导入导出数据库

一、导出数据库 1.新建一个.bak的文本 右击数据库--》Tasks--》BackUp--》Remove原来的数据库--》Add后选择之前建立的.bak档 二、导入数据库 1.右击数据库--》Tasks--》Restore--》Database--》From device--》勾选数据库之后--》点击左上角Options--》点击 --》OK覆盖 转载于…

如何使YouTube视频连续循环播放

Should you need a YouTube video on a continuous loop, a few methods can help you keep repeating a video without having to start it over manually. Here’s how to do it. 如果您需要连续循环播放YouTube视频&#xff0c;可以采用以下几种方法来继续播放视频&#xff…