目录:
题目:
题意:
给出一个等差数列、一个等比数列,求在一个范围内有几个数在这两个数列中
分析:
对于等差数列,十分好算,直接数论走一波:
而等比数列,我们可以直接枚举,因为等比数列的每个数是按几何倍进行增长,所以不必担心会TLE,在枚举时可以用等差公式进行判重
当然,数据还有些坑…
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
inline LL read() {
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
int main()
{
LL a,b,c,d,range,ans=0;
cin>>a>>b>>c>>d>>range;
if(a<=range) ans=(range-a)/b+1;//数据很坑...
while(c<=range)
{
if(c<a||(c-a)%b) ans++;//若没有出现过,则统计
c*=d;
if(d==1) break;//大坑!!!
}
cout<<ans;
fclose(stdin);
fclose(stdout);
return 0;
}