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/LDIGIT1 #746

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

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

https://luyencode.net/problem/LDIGIT1

zhongli2k6 commented 2 years ago

code AC C++ màu mè ai cần: https://ideone.com/FrBMvW

ghost commented 2 years ago

code AC C++ màu mè ai cần: https://ideone.com/FrBMvW

bạn có thể giải thích thuật toán này giúp mình đc k

Gilgamesh-hoang commented 2 years ago

Đây là lời giải Java của mình đã AC. Chuyện gì khó có Java

Xem code AC

``` import java.math.BigInteger; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n =sc.nextInt(); BigInteger fact =BigInteger.ONE; // tính giai thừa if (n != 0 || n != 1) { for (int i = 2; i <= n ; i++) { fact = fact.multiply(BigInteger.valueOf(i)); } } // System.out.println(fact); System.out.println(check(fact)); } static BigInteger check(BigInteger giaiThua) { BigInteger du; while (true) { du = giaiThua.remainder(BigInteger.valueOf(10));// có nghĩa là: du = du % 10; boolean b = du.equals(BigInteger.valueOf(0));// nếu du bằng 0 thì bỏ qua, không bằng thì break và return du if(b==false ) break; else giaiThua= giaiThua.divide(BigInteger.valueOf(10)); } return du; } } ```

AnnNaa0511 commented 1 year ago

Gợi ý : Chữ số cuối cùng khác không của n! là chữ số cuối cùng của ( 2^p)p!r! Với p=(int)n/5, r=n%5.

Xem code AC

```cpp #include using namespace std; long long last_factory(int n,int hai_mu[],int giai_thua[]){ if(n==0) return 1; int p=n/5; int r=n%5; if(p==0) return((long long)1*giai_thua[r]*last_factory(p,hai_mu,giai_thua))%10; return ((long long)hai_mu[p%4]*giai_thua[r]*last_factory(p,hai_mu,giai_thua))%10; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int hai_mu[4]={6,2,4,8}; int giai_thua[5]={1,1,2,6,4}; int n; cin>>n; cout<

sseu18042004 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 #define ll unsigned long long int #define fast() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define el cout<<"\n" using namespace std; int main() { fast(); ll n; cin>>n; if (n==0 || n==1) { cout<<0; return 0; } ll res=1; for (int i=2;i<=n;i++) { res*=i; if (res%10==0) { while(res%10==0) { res/=10; } } res%=1000; } while(res%10==0) { res/=10; } cout<