题目就不再发了,大致意思就是给你一个十进制数n,算出阶乘后转换成K进制的数,你来算一下它的位数。

坑点在哪呢,就是这个数可能算阶乘的时候没放弄了,比如1000000,做过最多单算阶乘的题也就是让你算到10000,所以这个如果按正常步骤来写肯定不行啦。

本题主要运用两个定理:

1丶 十进制位数就是 (int)log10(n),比如,1234,就是4,55555位数就是5。

对应K进制位数就是logk(n),但是math.h或者库函数里边log函数的底数只有固定的几个能直接用的,所以需要用到换底公式啦

2丶:loga(n)=logm(n)/logm(a)=ln(n)/ln(a);

3丶:核心思想  要求K进制位数:logk(n!)=ln(n!)/lnk + 1={ln(1)+ln(2)+ln(3)+...+ln(n)}/lnk  +  1;

AC代码如下:大家看的时候可以自己再理解理解看看有没有更好的方法来解这道题啦,我这水平也有限,代码可能还不够完善呢。

#include<stdio.h>
#include<math.h>
#include<string.h>
#define ll long long
double aa[];
int main()
{ int t,c,m,n,i;
double ww;
scanf("%d",&t);
memset(aa,,sizeof(aa));
for(i=;i<=;i++)
aa[i]+=aa[i-]+log(i);//打个表来存一下前1000000个数的log(阶乘),会节省很多时间的
for(int i=;i<=t;i++)
{
scanf("%d%d",&m,&n);
if(m==)
printf("Case %d: 1\n",i);
else
{
ww=aa[m];//此处两行就是上边我介绍的核心思想了
ww=ww/log(n)+;//至于为什么+1,自己再想想啦
printf("Case %d: %d\n",i,(int)ww);
}
}
return ;
}

Digits of Factorial LightOJ - 1045的更多相关文章

  1. Digits of Factorial LightOJ - 1045(数学题?)

    原文地址: https://blog.csdn.net/fenghoumilin/article/details/52293910 题意:求 n 的阶乘在 base 进制下的位数,这里有一个简单的方法 ...

  2. 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 ...

  3. LightOJ Beginners Problems 部分题解

    相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...

  4. 专题[vjudge] - 数论0.1

    专题[vjudge] - 数论0.1 web-address : https://cn.vjudge.net/contest/176171 A - Mathematically Hard 题意就是定义 ...

  5. LOJ N!在不同进制的位数

    lightoj1045 - Digits of Factorial (N!不同进制的位数) 对于一个B进制的数,只需要对其取以B的对数就可以得到他在B进制情况下的位数(取了对数之后可能为小数,所以还需 ...

  6. Problem 34

    Problem 34 https://projecteuler.net/problem=34 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 1 ...

  7. 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 ...

  8. Intelligent Factorial Factorization LightOJ - 1035(水题)

    就是暴力嘛...很水的一个题... 不好意思交都... #include <iostream> #include <cstdio> #include <sstream&g ...

  9. CodeForces 515C. Drazil and Factorial

    C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. nmap扫描验证多种漏洞

    nmap在Kali Linux中是默认安装的.它不仅可以用来确定目标网络上计算机的存活状态,而且可以扫描各个计算机的操作系统.开放端口.服务,还有可能获得用户的证书. 命令结构: nmap -sS - ...

  2. MyEclipse 10.7(版本:eclipse 3.7.x-Indigo系列)安装PyDev 4.5.4插件

    解压安装路径结构如截图所示: 安装后重启:

  3. Python3.5+PyQt5多线程+itchat实现微信防撤回桌面版代码

    weChatThread线程类 之前一直不会python多线程,写这个程序的时候,发现不用多线程会陷入无限未响应状态.于是学了半天python多线程,但是在主函数里写的时候,发现一个问题,Ui主线程和 ...

  4. P1357 花园

    洛咕原题 题解 状压dp+矩乘 首先看到题目说M<=5,这么小的数据明显可以用状压保存相邻状态,于是可以得到一个80分的dp: 先筛出所有可用的状态,然后建立一个矩阵保存可转移的状态,再然后把每 ...

  5. Mysql 利用拷贝data目录文件的方式迁移mysql数据库

    Mysql 利用拷贝data目录文件的方式迁移mysql数据库 步骤如下: 1.首先要确定data目录 这个问题困扰了我很久,因为网上的帖子大部分只是说拷贝mysql数据库目录下的data文件夹中的数 ...

  6. oracle /*+ SYS_DL_CURSOR */ 这个hint

    之前一直都没使用过 /*+ SYS_DL_CURSOR */这个提示,今天下午在排查一个性能问题的时候,发现出问题的session在执行一个带了SYS_DL_CURSOR提示的语句,类似于: 经查这个 ...

  7. python框架相关问题

    面试其他篇 目录: 1.1

  8. es数据迁移脚本(python)

    #!/usr/bin/python # -*- coding: UTF-8 -*- # 文件名:indiceCreate.py import sys import base64 import time ...

  9. PHP 重置数组为连续数字索引的几种方式

    原文链接:https://blog.csdn.net/zhang197093/article/details/78606916 推荐的方式  array_values 方法 这样方式无论对普通数组还是 ...

  10. PyCharm笔记之首次安装和激活

    转载:http://www.cnblogs.com/Ivyli4258/p/7440147.html PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其 ...