Description
求以a为首项,d为公差的等比数列中第n个素数
Input
多组输入,每组用例三个整数a,d,n,以0 0 0结束输入
Output
对于每组用例,输出以a为首项,d为公差的等比数列中第n个素数
Sample Input
367 186 151
179 10 203
271 37 39
103 230 1
27 104 185
253 50 85
1 1 1
9075 337 210
307 24 79
331 221 177
259 170 40
269 58 102
0 0 0
Sample Output
92809
6709
12037
103
93523
14503
2
899429
5107
412717
22699
25673
Solution
简单题,暴力搜索即可
Code
#include<stdio.h>
#include<math.h>
typedef long long ll;
int is_prime(ll x)//判断x是不是素数
{
ll i;
if(x==1)//1不是素数
return 0;
for(i=2;i<=sqrt((double)x);i++)
if(x%i==0)
return 0;;
return 1;
}
int main()
{
ll a,d,n,res;
while(scanf("%lld%lld%lld",&a,&d,&n))
{
if(a==0&&d==0&&n==0)
break;
res=0;
while(1)
{
if(is_prime(a))
res++;
if(res==n)
break;
a+=d;
}
printf("%lld\n",a);
}
return 0;
}