• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

1045 - Digits of Factorial(数论)

题意:给定n、k,求出n的阶乘转化为k进制一共有几位。

思路:log(a*b)=log(a)+log(b)..............

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1045

 

View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <string>
 5 #include <algorithm>
 6 #include <iostream>
 7 using namespace std;
 8 const int N=1000010;
 9 
10 double sum[N]={0,0};
11 
12 int main(){
13     
14 //    freopen("data.in","r",stdin);
15 //    freopen("data.out","w",stdout);
16     
17     int t,i,j,n,k;
18     scanf("%d",&t);
19     for(i=2;i<N;i++)
20         sum[i]=sum[i-1]+log10(i);    // log(a*b)=log(a)+log(b)
21     for(i=1;i<=t;i++){
22         scanf("%d%d",&n,&k);
23         int ans=sum[n]/(log10(k*1.0))+1;
24         printf("Case %d: %d\n",i,ans);
25     }
26     return 0;
27 }

 

 

posted @ 2012-05-14 11:10  Hug_Sea  阅读(162)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3