题解 SP24 FCTRL2 - Small factorials
双倍经验。
题意
给\(t\) 组数据,求每组数据中\(n\) 的阶乘。
思路
\(n≤100\) 。
\(100!\) 肯定爆int128,所以高精呗。
那么就是一个阶乘的板子了,应该不难的吧。
具体实现见代码。
\(\sf {Code}\)
(变量名有点奇怪……)
#include<cstdio>
#include<string.h>
using namespace std;
int n,a[91001],t,q;
int main()
{
scanf("%d",&q);
while(q--)
{
scanf("%d",&n);
memset(a,0,sizeof(a));//注意初始化
a[1]=1;
int len=1;
for(int i=1;i<=n;++i)//枚举1~n
{
t=0;//进位变量初始化
for(int j=1;j<=len;++j) //乘上当前的数
{
a[j]=a[j]*i+t;
t=a[j]/10;
a[j]=a[j]%10;
if(t&&j>=len)
++len;//如果有进位,len+1
}
}
for(int i=len;i>=1;--i)
printf("%d",a[i]);//输出结果
printf("\n");
}
return 0;
}
end.
题解 SP24 FCTRL2 - Small factorials的更多相关文章
- [UVA160]Factors and Factorials 题解
前言 这道题目本身毫无技术含量珂言,但是输出格式珂以调一年 题解 这道题让我们求\(N!\)中每个质数的个数. 一种方法是直接模拟,枚举\(N!\)中的每个元素,然后暴力查看每个数含有有多少质数. 但 ...
- Small factorials Solved Problem code: FCTRL2
import sys def fact(n): final = n while n > 1: final *= n - 1 n -= 1 return final #逻辑严谨,不要忘了retur ...
- 【CodeChef】Small factorials(BigInteger笔记)
You are asked to calculate factorials of some small positive integers. Input An integer t, 1<=t&l ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- 【USACO 3.2】Factorials(阶层非零尾数)
题意:输出n的阶层最后一个非0数. 题解:可以把5和2的个数算出来,每次把5和2都除掉,最后乘上比5多出来的2.我的解法是,每次把尾巴的0去掉,并且保留3位,算到最后取尾数就可以了.. /* TASK ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
随机推荐
- Luogu2018 消息传递 (树形DP)
贪心优先子树较多者. #include <iostream> #include <cstdio> #include <cstring> #include <a ...
- pytest-fixture执行顺序
作用域-scope 作用域越大,越先执行,session>package>module>class>function. 是否自动调用fixture 自动调用(autouse=T ...
- Spring源码 15 IOC refresh方法10
参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...
- MyBatis 01 概述
官网 http://www.mybatis.org/mybatis-3/zh/index.html GitHub https://github.com/mybatis/mybatis-3 简介 MyB ...
- 关于python如何引用excel文件
关于python如何引用excel文件 import pandas as pd #引用pandas库,as:将pandas简写为pd Nowcoder = pd.read_excel("1. ...
- springBoot项目实现发送邮件功能
需要的依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- dentry的引用计数不对导致的crash
[17528853.189372] python invoked oom-killer: gfp_mask=0xd0, order=0, oom_score_adj=-998[17528853.189 ...
- 美丽的神话 flac 成龙/金喜善 美丽的神话 mp3 韩红/孙楠
这里分享从网上收集的俩个版本的歌,都很不错,有兴趣的可以听听 以下是成龙/金喜善 flac 版本,音质不错: 美丽的神话成龙/金喜善解开我最神秘的等待星星坠落风在吹动终于再将你融入怀中两颗心颤抖相信我 ...
- HTML短链接
短链接跳转方法 新建一个目录名称就是短链接字符列如:1 创建一个index.html文件里面添加代码如下 <script type="text/javascript"> ...
- 抛砖系列之git仓库拆分工具git-filter-repo
最近负责把团队内的git仓库做了一次分拆,解锁一个好用的工具git-filter-repo,给大伙抛砖一波,希望以后遇到类似场景时可以信手拈来. 背景 笔者团队目前是把业务相关的java项目都放到了一 ...