1.遇到需要用大数处理的问题,一定要先去思考能避开大数的程序,不要上来就用c++大数模板或java大数函数,前者敲起来繁琐,后者效率太低。

#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    long long k,b,n,t,z;
    while(cin >> k >> b >> n >>t){
        long long x=1;
        int cou=0;
        while(x<=t && cou<=n){
            x=k*x+b;
            cou++;
        }
        cout << n-cou+1 <<endl;
    }
    return 0;
}

2.pow,log这种处理double的东西尽量不要和整型运算混用,会造成精度缺失以导致wa的。

3.遇到不等关系,为了防止精度缺失,最好还是一步一步踏踏实实地运算。

#include <iostream>
#include <math.h>
using namespace std;
#include <stdio.h>
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("WA.txt","w",stdout);
    int n;
    double k;
    while(cin >> n >>k){
        int l=1,r=n;
        int mid=-1;
        while(l<r){
            //cout << l <<" "<< r <<endl;
            mid=(l+r)/2;
            long long p=0;
            long long kk=1;
            while(mid>=kk){
                kk*=k;
                p++;
            }
            long long sum=0;
            for(int i=0;i<=p;i++){
                kk=1;
                for(int j=0;j<i;j++){
                    kk*=k;
                }
                sum+=mid/kk;
            }
            if(sum>=n) r=mid;
            else l=mid+1;
        }
        cout << r <<endl;
    }
    return 0;
}