题目就不再发了,大致意思就是给你一个十进制数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. Spring MVC前传递和后端接收的参数名不一致处理方式

    前端传递的变量和后端接收的变量名字不一致时,用注解@RequestParam来实现数据的传递 例如:@RequestParam(value="id") //实现商品的分类目录展现 ...

  2. MySQL底层索引剖析

    1:Mysql索引是什么 mysql索引: 是一种帮助mysql高效的获取数据的数据结构,这些数据结构以某种方式引用数据,这种结构就是索引.可简单理解为排好序的快速查找数据结构.如果要查“mysql” ...

  3. Eloquent JavaScript #09# Regular Expressions

    索引 Notes js创建正则表达式的两种方式 js正则匹配方式(1) 字符集合 重复匹配 分组(子表达式) js正则匹配方式(2) The Date class 匹配整个字符串 Choice pat ...

  4. Python建立多线程任务并获取每个线程返回值

    1.进程和线程 (1)进程是一个执行中的程序.每个进程都拥有自己的地址空间.内存.数据栈以及其他用于跟踪执行的辅助数据.进程也可以派生新的进程来执行其他任务,不过每个新进程都拥有自己的内存和数据栈,所 ...

  5. django 上传文件及反馈信息

    from django.shortcuts import render,HttpResponse from django.views import View from Fiskars.models i ...

  6. scrapy进阶(CrawlSpider爬虫__爬取整站小说)

    # -*- coding: utf-8 -*- import scrapy,re from scrapy.linkextractors import LinkExtractor from scrapy ...

  7. 常用MarkDown标记

    1:加粗 两个*号 加粗 2:代码段 三个` 代码段

  8. JVM优化-JVM参数配置

    配置方式: java [options] MainClass [arguments] options - JVM启动参数. 配置多个参数的时候,参数之间使用空格分隔. 参数命名: 常见为 -参数名 参 ...

  9. linux 文件同步

    ref: https://www.cnblogs.com/MacoLee/p/5633650.html https://wenda.so.com/q/1505308236213470 http://b ...

  10. topcoder srm 713 div1

    problem1 link 如果$a^{b}=c^{d}$,那么一定存在$t,x,y$使得$a=t^{x},c=t^{y}$.一旦$t,x,y$确定,那么可以直接计算出二元组$b,d$有多少.对于$t ...