Digits of Factorial LightOJ - 1045(数学题?)
原文地址: https://blog.csdn.net/fenghoumilin/article/details/52293910
题意:求 n 的阶乘在 base 进制下的位数,这里有一个简单的方法,就是log10(n)+ 1就是 n 的在十进制下的位数(想一下 为什么。。。),由此可知 log base(n)+ 1 就是n在base 进制下的位数,再根据换底公式,log base(n) == log(n)/ log(base),这里让求的是阶乘,根据log的原理呢,就有log base (n!) == ( log(n) + log(n-1) + log(n-2) + 。。。。+ log(1)) / log(base)。用 sum 数组存一下 log(n!) 就可以快速的求出了
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = + , INF = 0x7fffffff;
double num[maxn]; //注意类型 int main()
{
num[] = ;
for(int i=; i<maxn; i++)
num[i] = num[i-] + log(1.0 * i);
int T, kase = ;
scanf("%d",&T);
while(T--)
{
int n, base;
scanf("%d%d",&n,&base);
int ans = num[n]/log(1.0 * base) + ;
printf("Case %d: %d\n", ++kase, ans);
} return ;
}
Digits of Factorial LightOJ - 1045(数学题?)的更多相关文章
- Digits of Factorial LightOJ - 1045
题目就不再发了,大致意思就是给你一个十进制数n,算出阶乘后转换成K进制的数,你来算一下它的位数. 坑点在哪呢,就是这个数可能算阶乘的时候没放弄了,比如1000000,做过最多单算阶乘的题也就是让你算到 ...
- light oj 1045 - Digits of Factorial K进制下N!的位数
1045 - Digits of Factorial Factorial of an integer is defined by the following function f(0) = 1 f(n ...
- LightOJ 1245 数学题,找规律
1.LightOJ 1245 Harmonic Number (II) 数学题 2.总结:看了题解,很严谨,但又确实恶心的题 题意:求n/1+n/2+....+n/n,n<=2^31. ...
- LightOJ Beginners Problems 部分题解
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...
- 专题[vjudge] - 数论0.1
专题[vjudge] - 数论0.1 web-address : https://cn.vjudge.net/contest/176171 A - Mathematically Hard 题意就是定义 ...
- LOJ N!在不同进制的位数
lightoj1045 - Digits of Factorial (N!不同进制的位数) 对于一个B进制的数,只需要对其取以B的对数就可以得到他在B进制情况下的位数(取了对数之后可能为小数,所以还需 ...
- Problem 34
Problem 34 https://projecteuler.net/problem=34 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 1 ...
- LeetCode172 Factorial Trailing Zeroes. LeetCode258 Add Digits. LeetCode268 Missing Number
数学题 172. Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. N ...
- 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
随机推荐
- [C++]linux下实现ls()函数遍历目录
转载请注明原创:http://www.cnblogs.com/StartoverX/p/4600794.html 需求:在linux下遍历目录,输出目录中各文件名. 在linux下遍历目录的相关函数有 ...
- [codeForce-1006C]-Three Parts of the Array (简单题)
You are given an array d1,d2,…,dnd1,d2,…,dn consisting of nn integer numbers. Your task is to split ...
- c++三大概念要分清--重载,隐藏(重定义),覆盖(重写)
重载,隐藏(重定义),覆盖(重写)—这几个名词看着好像很像,不过其实一样都不一样!! 综述: 说明:覆盖中的访问修饰符可以不同是指可以不用显示地用virtual:当访问修饰符改为const或者stat ...
- 如何在window服务器上搭建一个能代替ftp的传输工具
通常对于服务器上的文件管理和数据传输都是利用ftp来实现,但随着存储技术的发展,数据资产的存储规模和复杂程度不断提高,传统的ftp传输显得有笨重.今天给大家介绍一款能够取代ftp的在线文档管理软件—— ...
- centos6.9+lnmp1.5环境部署swoole记录
hiredis下载地址:https://github.com/redis/hiredis/releasesunzip hiredis-v0.13.3.zipmake -jsudo make insta ...
- Mysql数据库的四大特性
Mysql数据库事务的四大特性(ACID) 事务:把一组密不可分的操作系列集合在一起,这些操作要么全部执行,要么全部不执行. 1.原子性:事务是内定义的操作是一个整体,是不可分割的. 2.一致性:事务 ...
- NuGet 让程序集版本变得混乱
之前引用的 System.Net.Http.Formatting ,是依赖于 System.Net.Http 2.0的. 更新引用后它是依赖于 System.Net.Http 4.0 的.而且一 ...
- 一个demo 理解 vuex
相比接触vue的同学们已经看了官方文档了.这里我用一个简单的demo来阐述下vuex的知识点,虽然简单,但是容易理解.也加深自己的记忆. 用脚手架建立个项目vue init webpakc-simpl ...
- 探路者 FInal冲刺中间产物
版本控制 https://git.coding.net/clairewyd/toReadSnake.git 版本控制报告 http://www.cnblogs.com/linym762/p/79976 ...
- teamwork 2
1.访问上学期项目团队,学习他们的得失. 上学期学长们有一个项目是学霸系统,在看过了学长们的相关博客后,我们可以感受到学长们确实花费了不少心思,也看到了许多值得我们学习的地方. 首先,学长们在项目开始 ...