luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/FIBO2021 #698

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Tìm số thứ N - Luyện Code Online

https://luyencode.net/problem/FIBO2021

chatctt commented 2 years ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

#include using namespace std; int main() { int a,b,f[1000000],n; cin>>a>>b>>n; f[1]=a; f[2]=b; for(int i=3;i<=n;i++) { f[i]=f[i-1]+f[i-2]; f[i]%=2021; } cout<

danh2006 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int a, b, n; cin >> a >> b >> n; int f[n]; f[1]=a, f[2]=b; for(int i=3;i<=n;i++){ f[i]=f[i-1]%2021+f[i-2]%2021; } cout << f[n]%2021 << endl; }

NguyenTrong17070 commented 1 year ago

include <bits/stdc++.h>

define int long long int

define goodspeed ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std; signed main(){

goodspeed;
int a,b,n;
cin>>a>>b>>n;
int f[n+1];
f[1]=a;
f[2]=b;
for(int i=3;i<=n;i++)
{
    f[i]=(f[i-1]+f[i-2])%2021;
}
cout<<f[n]<<endl;

}