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/FH_04_04 #220

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Chi tiết bài tập - Luyện Code Online

https://luyencode.net/problem/FH_04_04

Tean267 commented 3 years ago

b cho mình hỏi chút là chỗ checkfibo sao (fibo(i)>n mà không phải khác n ạ

hieuguyen07012004 commented 3 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

```cpp #include using namespace std; int sum (unsigned long long n) { int sum=0; if (n<=9) return n; while (n>0) { sum+=n%10; n/=10; } return sum; } bool prime (unsigned long long n) { if (n<2) return false; else { for (int i=2; i*i<=n; ++i) { if (n%i==0) return false; } } return true; } int main() { unsigned long long a, b, fibo[100000], f[100000], dem=0; cin >> a >> b; fibo[0]=0; fibo[1]=1; fibo[2]=1; for (int i=3; i<=b/2; ++i) { fibo[i]=fibo[i-2]+fibo[i-1]; } for (int i=0; i<=fibo[b]; ++i) { f[i]=0; } for (int i=0; i<=b/2; ++i) { ++f[fibo[i]]; } for (int i=a; i<=b; ++i) { if (prime(i) && f[sum(i)]>=1) cout << i << " "; } return 0; } ```