zoukankan      html  css  js  c++  java
  • BNU 13259.Story of Tomisu Ghost 分解质因子

    Story of Tomisu Ghost

    It is now 2150 AD and problem-setters are having a horrified time as the ghost of a problem-setter from the past, Mr. Tomisu, is frequently disturbing them. As always is the case in most common ghost stories, Mr. Tomisu has an unfulfilled dream: he had set 999 problems throughout his whole life but never had the leisure to set the 1000th problem. Being a ghost he cannot set problems now so he randomly asks problem-setters to complete one of his unfinished problems. One problem-setter tried to convince him saying that he should not regret as 999 is nowhere near 1024 (210) and he should not worry about power of 10 being an IT ghost. But the ghost slapped him hard after hearing this. So at last one problem setter decides to complete his problem:

    "n! (factorial n) has at least t trailing zeroes in b based number system. Given the value of n and t, what is the maximum possible value of b?"

     

    Input

    Input starts with an integer T (≤ 4000), denoting the number of test cases.

    Each case contains two integers n (1 < n ≤ 105) and t (0 < t ≤ 1000). Both n and t will be given in decimal (base 10).

     

    Output

    For each case, print the case number and the maximum possible value of b. Since b can be very large, so print b modulo 10000019. If such a base cannot be found then print -1instead.

     

    Sample Input

    Sample Input

    Output for Sample Input

    4

    1000 1000

    1000 2

    10 8

    4 2

    Case 1: -1

    Case 2: 5227616

    Case 3: 2

    Case 4: 2

    Source

    题意:给你一个n,t,  n的阶乘在b进制下的数大小,数尾有t个0,问最大的b是多少,不存在b输出-1;

    题解:数尾有t个0,也就是对于b有t倍的关系,我们将1-n内所有质因子的个数找出,是否有大于等于t的就可以加入答案,否则-1

    ///1085422276
    #include<bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){
            if(ch=='-')f=-1;ch=getchar();
        }
        while(ch>='0'&&ch<='9'){
            x=x*10+ch-'0';ch=getchar();
        }return x*f;
    }
    //****************************************
    const double PI = 3.1415926535897932384626433832795;
    const double EPS = 5e-9;
    #define maxn 100000+5
    #define mod 10000019
    
    int n,t,H[maxn],HH[maxn];
    vector<int >G[maxn],P;
    ll pows(ll x,ll tt) {
        ll tmp=1;
       for(int i=1;i<=tt;i++) {
         tmp=(tmp*x)%mod;
       }
       return tmp;
    }
    int main() {
        int an=0;mem(HH);
        for(int i=2;i<=100000;i++) {
            if(!HH[i]) {P.pb(i);
            for(int j=i+i;j<=100000;j+=i) {
                        HH[j]=1;
            }
          }
        }
        int T=read(),oo=1;
        while(T--) {
            mem(H);
            int flag=0;
           n=read(),t=read();
           printf("Case %d: ",oo++);
           ll ans=1;
             for(int k=0;k<P.size()&&P[k]<=n;k++) {
                 ll c=P[k],tt=0;
                 ll y=n/z;
                  while(y) {
                    tt+=y;
                    y=y/z;
                  }
                if(tt>=t){
                        flag=1;
                    ans=(ans*pows(c,tt/t))%10000019;
                }
             }
            if(!flag) printf("-1
    ");
            else
                printf("%lld
    ",ans);
        }
        return 0;
    }
    代码
  • 相关阅读:
    Spring3+hibernate4+struts2整合的 过程中发生如下错误
    使用HQL语句的按照参数名字查询数据库信息的时候 “=:”和参数之间不能存在空格,否则会报错
    org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.mysql.jdbc.Driver class not found
    Java多线程编程:
    数据库连接池的工作原理
    Oracle数据库表的备份和数据表的删除操作
    数据库连接池
    Mysql登录异常的一个问题:
    2019年终总结
    设计模式入门-简单工厂模式
  • 原文地址:https://www.cnblogs.com/zxhl/p/4981152.html
Copyright © 2011-2022 走看看