2012年南海初中竞赛 数列

题目

这里写图片描述


解题思路

模拟


代码

#include<cstdio>
#include<iostream>
using namespace std; 
long long a,b,c,d,ans,uppe; 
int main()
{
    cin>>a>>b>>c>>d>>uppe; 
    if (a<=uppe) ans=(uppe-a)/b+1; //等差数列求项数
        while (c<=uppe) //枚举等比数列
        {
         if ((c-a)%b!=0||c<a) ans++; //判重
         c*=d;  
         if (d==1) break; //特判
        }   
    cout<<ans; //输出,因为数字较大,用cout
}

猜你喜欢

转载自blog.csdn.net/qq_39897867/article/details/79938800