b971 等差數列
b971 等差數列
| 解題思路 : 如程式中註解
| 程式碼 :
/*
b971 等差數列
skyblue
https://zerojudge.tw/ShowProblem?problemid=b971
AC (3ms, 352KB)
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
//加速輸入輸出程式
ios::sync_with_stdio(false);
cin.tie(0);
int a,m,d;
cin >> a >> m >>d;
int n = 1 + (m-a)/d; //計算總項數
for(int i=0; i<n; i++){
cout << a <<" ";
a += d; //輸出1數後加上公差
}
return 0;
}
/*範例輸入 #1
1 9 2
範例輸出 #1
1 3 5 7 9
*/
留言
張貼留言