题目链接

题意:

多组数据输入也就是C++中的:

int n;
while (cin >> n)
{
代码块
}

对于每个数据输出其阶乘的各位上的数字之和。大眼一看,没有思路,那就百度把。

百度解法:

我们进行大表,队1到1000每个数的阶乘进行计算,然后存储到一个sum数组中去。眨眼一看,好像阶乘求不到1000啊!没有关系,我们用一个很长的数组进行存储,让后依次对每位进行进制转换,然后统计每位数的和。

    a[1][1] = 1;
sum[1] = 1;
for (int i = 2; i <= 1000; i++)
{
for (int j = 1; j <= 3000; j++)
{
a[i][j] = a[i - 1][j] * i;
} for (int j = 1; j <= 3000; j++)
{
if (a[i][j] > 9)
{
a[i][j + 1] += (a[i][j] / 10);
a[i][j] = a[i][j] % 10;
}
}
for (int j = 1; j <= 3000; j++)
{
sum[i] += a[i][j];
}
}

那么,这道题目也就到此为止了:

#include <bits/stdc++.h>
#define int long long
using namespace std; const int N = 10000;
int a[4000][N], sum[N]; signed main()
{
a[1][1] = 1;
sum[1] = 1;
for (int i = 2; i <= 1000; i++)
{
for (int j = 1; j <= 3000; j++)
{
a[i][j] = a[i - 1][j] * i;
} for (int j = 1; j <= 3000; j++)
{
if (a[i][j] > 9)
{
a[i][j + 1] += (a[i][j] / 10);
a[i][j] = a[i][j] % 10;
}
}
for (int j = 1; j <= 3000; j++)
{
sum[i] += a[i][j];
}
} int n;
while (cin >> n)
{
cout << sum[n] << endl;
} return 0;
}

I Love Big Numbers !(高精度)的更多相关文章

  1. LeetCode 第二题 Add Two Numbers 大整数加法 高精度加法 链表

    题意 You are given two non-empty linked lists representing two non-negative integers. The digits are s ...

  2. poj 2325 Persistent Numbers (贪心+高精度)

    把输入数字每次从9-2除,能整除则记录该数字,最后从小到大输出. 应该算是水题,不过窝第一次写高精度除法,虽然1A,不过中间改了好多次. /****************************** ...

  3. POJ 2325 Persistent Numbers#贪心+高精度除法

    (- ̄▽ ̄)-* 这道题涉及高精度除法,模板如下: ]; ];//存储进行高精度除法的数据 bool bignum_div(int x) { ,num=; ;s[i];i++) { num=num*+ ...

  4. 【贪心】【高精度】zoj3987 Numbers

    题意:给你一个数n,让你找m个非负整数,使得它们的和为n,并且按位或起来以后的值最小化.输出这个值. 从高位到低位枚举最终结果,假设当前是第i位,如果m*(2^i-1)<n的话,那么说明这一位如 ...

  5. POJ 1504 Adding Reversed Numbers (水题,高精度整数加法)

    题意:给两个整数,求这两个数的反向数的和的反向数,和的末尾若为0,反向后则舍去即可.即若1200,反向数为21.题目给出的数据的末尾不会出现0,但是他们的和的末尾可能会出现0. #include &l ...

  6. URAL 1012 K-based Numbers. Version 2(DP+高精度)

    题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...

  7. POJ 1625 Censored!(AC自动机+DP+高精度)

    Censored! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6956   Accepted: 1887 Descrip ...

  8. [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)

    树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...

  9. 数论 - 高精度Fibonacci数 --- UVa 10183 : How Many Fibs ?

    How many Fibs? Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := f n ...

  10. SGU-169 Numbers(找规律)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=169 解题报告: P(n)定义为n的所有位数的乘积,例如P(1243)=1*2*3* ...

随机推荐

  1. 大家都能看得懂的源码 - 那些关于DOM的常见Hook封装(一)

    本文是深入浅出 ahooks 源码系列文章的第十四篇,该系列已整理成文档-地址.觉得还不错,给个 star 支持一下哈,Thanks. 上一篇我们探讨了 ahooks 对 DOM 类 Hooks 使用 ...

  2. omc.

    OMC 099(4b) D 因为 \((abc)^{\dfrac 13} \le \dfrac{a+b+c}3\)(基本不等式),将 \(a = xy, b = yz, c = xz\) 代入得到 \ ...

  3. Linux 压缩、解压缩命令

    Linux 压缩.解压缩命令 tar 语法命令 tar [options-] [files] options: 选择 描述 -A 追加tar文件至归档 -c 创建一个新文档 -d 找出归档和文件系统的 ...

  4. 2022CSP-J初赛游记

    2022年9月16日: 下午,在学校集训,刘洋让我看了一下时间,突然发现,距离初赛就剩2天了...... 晚上,辅导班的老师对我们进行最后的培训,做了2套有道小图灵模拟题,但是做的不理想,很慌. 20 ...

  5. vscode用户自定义代码中如何表示table空格

    "Print to phpfuntion": { "scope": "php", "prefix": "pfu ...

  6. ProxySQL的双层用户认证机制

    转载自:https://www.likecs.com/show-203802325.html 如果使用了ProxySQL来做中间路由,那么与我们平时登录数据库有一些区别:平时我们直接使用数据库的用户密 ...

  7. Kubernetes里的Service是如何工作的

    Service是Kubernetes接入层的一种抽象资源,它为我们提供了一种固定的.统一的访问接口地址和负载均衡能力,这时可能会想到,当时使用docker-compose的时候,不存在Service概 ...

  8. 记一次TIME_WAIT网络故障

    文章转载自:https://blog.51cto.com/dngood/988968

  9. 索引模板和动态索引模板 (Index Template和Dynamic Template)

    相关阅读 Index Templates https://www.elastic.co/guide/en/elasticsearch/reference/7.1/indices-templates.h ...

  10. Spring Boot 项目转容器化 K8S 部署实用经验分享

    转载自:https://cloud.tencent.com/developer/article/1477003 我们知道 Kubernetes 是 Google 开源的容器集群管理系统,它构建在目前流 ...