当前位置: 首页 > wzjs >正文

开县网站建设网站建设实验原理

开县网站建设,网站建设实验原理,最近文章 wordpress,开发app软件多少钱博主主页:Yu仙笙 专栏地址:洛谷千题详解 目录 题目描述 输入格式 输出格式 输入输出样例 解析: C源码: Python源码: Java源码: Pascal源码: ------------------------------------------------…

博主主页:Yu·仙笙

专栏地址:洛谷千题详解

目录

题目描述

输入格式

输出格式

输入输出样例

解析: 

C++源码:

Python源码:

Java源码:

Pascal源码:


 -------------------------------------------------------------------------------------------------------------------------------

 -------------------------------------------------------------------------------------------------------------------------------

题目描述

用高精度计算出 S=1!+2!+3!+⋯+n!(n≤50)。

其中 ! 表示阶乘,定义为n!=n×(n−1)×(n−2)×⋯×1。例如,5!=5×4×3×2×1=120。

 -------------------------------------------------------------------------------------------------------------------------------

输入格式

一个正整数 n。

 -------------------------------------------------------------------------------------------------------------------------------

输出格式

一个正整数 S,表示计算结果。

 -------------------------------------------------------------------------------------------------------------------------------

输入输出样例

输入 #1

3

输出 #1

9

 -------------------------------------------------------------------------------------------------------------------------------

解析: 

 思路就是高精乘+高精加,就是把高精乘的模板套上去接着套高精加的模板,b=c=i的阶乘。

 -------------------------------------------------------------------------------------------------------------------------------

C++源码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
struct fantastic     //嗯,开始重载了
{int len,s[9999];fantastic(){memset(s,0,sizeof(s));len=1;}fantastic operator=(const char*num){len=strlen(num);for(int i=0;i<len;++i)s[i]=num[len-i-1]-'0';return *this;}fantastic operator=(const int num){char a[9999];sprintf(a,"%d",num);*this=a;return *this;}fantastic (const int num){*this=num;}fantastic (const char * num){*this=num;}fantastic operator+(const fantastic &a)   //这里在重载 “+” 的运算{fantastic c;c.len=max(len,a.len)+1;                //这里就是我们熟悉的竖式模拟了for(int i=0,x=0;i<c.len;++i){c.s[i]=s[i]+a.s[i]+x;x=c.s[i]/10;c.s[i]=c.s[i]%10;}if(c.s[c.len-1]==0)--c.len;return c;}fantastic operator * (const fantastic &x)           //然后再来波 “*” 的运算{fantastic c;c.len=len+x.len;                 //又是我们熟悉的竖式模拟for(int i=0;i<len;++i)for(int j=0;j<x.len;++j){c.s[i+j]+=s[i]*x.s[j];c.s[i+j+1]+=c.s[i+j]/10;c.s[i+j]%=10;}if(c.s[c.len-1]==0)--c.len;return c;}
};
ostream& operator<<(ostream &out,const fantastic& x)   //重载一下输出
{for(int i=x.len-1;i>=0;--i)cout<<x.s[i];return out;
}
istream& operator>>(istream &in,fantastic &x)       //重载一下输入
{char num[9999];in>>num;x=num;return in;
}
int main()         //然后就可以愉快的开始主程序啦
{int n;fantastic ans=0,num=1;cin>>n;for(int i=1;i<=n;i++){num=num*i;ans=ans+num;}cout<<ans<<endl;
}                                         //非常的简单明了

 -------------------------------------------------------------------------------------------------------------------------------

Python源码:

print(reduce(lambda x,y:x+y,[reduce(lambda x,y:x*y,range(1,i+1)) for i in range(1, int(raw_input())+1)]))

 -------------------------------------------------------------------------------------------------------------------------------

Java源码:

    private static final BigInteger[] INTEGERS = new BigInteger[51];static {INTEGERS[0] = new BigInteger("1");}public static void main(String[] args) {BigInteger result = new BigInteger("0");Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();for (int i = 1; i <= n; ++ i) {INTEGERS[i] = INTEGERS[i - 1].multiply(new BigInteger(String.valueOf(i)));result = result.add(INTEGERS[i]);}System.out.println(result);}

 -------------------------------------------------------------------------------------------------------------------------------

Pascal源码:

var a,b:array[1..1000] of int64;i,j,la,lb,n:longint;
procedure cheng(t:longint);//高精度乘单精度
var i:longint;
beginfor i:=1 to la doa[i]:=a[i]*t;for i:=1 to la dobegina[i+1]:=a[i+1]+a[i] div 10;a[i]:=a[i] mod 10;end;while a[la+1]>0 do inc(la);
end;
procedure jia;//高精度加法
var i:longint;
beginfor i:=1 to la dobeginb[i]:=b[i]+a[i];b[i+1]:=b[i+1]+b[i] div 10;b[i]:=b[i] mod 10;end;while b[lb+1]>0 do inc(lb);
end;
beginread(n);a[1]:=1;for i:=1 to n dobegincheng(i);jia;end;for i:= lb downto 1 dowrite(b[i]);
end.

 -------------------------------------------------------------------------------------------------------------------------------


文章转载自:

http://0gT25YN5.txxwm.cn
http://TvoyZxbo.txxwm.cn
http://l2FScNnx.txxwm.cn
http://pMGY6vRC.txxwm.cn
http://wdibrnvF.txxwm.cn
http://d8cF1QHz.txxwm.cn
http://5VqxGrTB.txxwm.cn
http://RDybmiQf.txxwm.cn
http://d938Sjcw.txxwm.cn
http://UIfhg6PX.txxwm.cn
http://gcm5huwr.txxwm.cn
http://yqURd7Rg.txxwm.cn
http://yKTiZ9lk.txxwm.cn
http://qHiKVU9j.txxwm.cn
http://HyXuH64z.txxwm.cn
http://EPb9gune.txxwm.cn
http://MbWVqrht.txxwm.cn
http://td6lNk8W.txxwm.cn
http://APdjaBBW.txxwm.cn
http://L8kUoIcm.txxwm.cn
http://skkIz87r.txxwm.cn
http://wqMmBq02.txxwm.cn
http://jLEFb7CM.txxwm.cn
http://SBBd7gkB.txxwm.cn
http://VV6mHlqy.txxwm.cn
http://C0H0MukC.txxwm.cn
http://Dmt3ALJr.txxwm.cn
http://Ee6BY8Cl.txxwm.cn
http://pHENBu01.txxwm.cn
http://1XoIHTEE.txxwm.cn
http://www.dtcms.com/wzjs/690342.html

相关文章:

  • 浙江省建设政务网站海外购物网站大全
  • angularjs 做团购网站大阳摩托车官网
  • 中文域名和网站的关系wordpress网站不收录
  • 微信电脑网站是什么原因android开发是做什么的
  • php+mysql网站开发...php做网站用什么软件好
  • 城乡建设杂志官方网站wordpress 登录后台
  • 织梦网站tel标签易优cms企业网站管理系统
  • 怎么在网站上做宣传云主机购买
  • 网站流量统计分析的维度包括太原网站制作公司飞向未来
  • 网站建设责任分工正规网站制作全包
  • 个人网站备案名称淘宝上的网站怎么做
  • 有没有做视频的网站南昌营销网站建设
  • 网站建设越秀seo推广方法
  • 网站后台做链接平台免费推广
  • 企业网站设计的基本内容包括哪些搭建漏洞网站
  • 网站建设技术流程图wordpress 自动发卡
  • 微网站和门户网站的区别wordpress好用插件推荐
  • 网站增加网页怎么用服务器搭建网站
  • 免费网站建设平台哪个平台可以免费做项目
  • 唐山建设网站网站设计师网站登录
  • 电子商务网站建设与管理实训报告延安商城网站开发设计
  • 安装网站到服务器建网站要备案
  • 齐全的赣州网站建设白城网站建设公司
  • 德阳响应式网站建设做生物学的网站
  • 一品猪网站开发遵义今天查出新冠
  • 山东建设厅造价员网站注册1000万公司每年费用多少
  • 南浔建设局网站长沙网站制作服务
  • 重庆电子商务网站建设合江县住房和城乡规划建设局网站
  • 一个企业做网站的意义网站分析报告范文2000
  • 做一个网站的基本步骤你对网络营销的理解