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/PTIT046 #861

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

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

https://oj.luyencode.net/problem/PTIT046

mcscoder commented 1 year ago

Bài này theo cách của mình:

Vậy ta có số bước là 2 Mình để code minh họa ở đây: https://ideone.com/0k8Imm Bạn nào chưa làm được tham khảo

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; #define ll long long #define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);srand(time(NULL)); template void read(H& head) { cin >> head; } template void read(H& head, T& ...tail) { cin >> head; read(tail...); } template void write(H head) { cout << head << '\n'; } template void write(H head, T ...tail) { cout << head << " "; write(tail...); } template void print(T ...tok) { write(tok...); return; } int gcd(ll a, ll b){ if(b == 0) return a; else return gcd(b, a % b); } void solve(){ ll a, b, cnt = 0; read(a, b); ll x = gcd(a, b); while(a != x){ if(a % 5 == 0 && (a - (a * 4 / 5)) % x == 0) a = a - (a * 4 / 5); else if(a % 3 == 0 && (a - (a * 2 / 3)) % x == 0) a = a - (a * 2 / 3); else if(a % 2 == 0 && (a / 2) % x == 0) a /= 2; else{ write("-1"); return; } cnt++; } while(b != x){ if(b % 5 == 0 && (b - (b * 4 / 5)) % x == 0) b = b - (b * 4 / 5); else if(b % 3 == 0 && (b - (b * 2 / 3)) % x == 0) b = b - (b * 2 / 3); else if(b % 2 == 0 && (b / 2) % x == 0) b /= 2; else{ write("-1"); return; } cnt++; } write(cnt); } int main(){ fast_io; solve(); return 0; }

sseu18042004 commented 1 year ago

test 2 là trường hợp đi với số 1 nha mọi người (1 3) ra 1.........(1,5) ra 1. 1 7 ra -1