日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #565 (Div. 3) A. Divide it!

發(fā)布時間:2023/12/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #565 (Div. 3) A. Divide it! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鏈接:

https://codeforces.com/contest/1176/problem/A

題意:

You are given an integer n.

You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times:

Replace n with n2 if n is divisible by 2;
Replace n with 2n3 if n is divisible by 3;
Replace n with 4n5 if n is divisible by 5.
For example, you can replace 30 with 15 using the first operation, with 20 using the second operation or with 24 using the third operation.

Your task is to find the minimum number of moves required to obtain 1 from n or say that it is impossible to do it.

You have to answer q independent queries.

思路:

優(yōu)先操作2, 再3,再5.
暴力即可。

代碼:

#include <bits/stdc++.h>using namespace std;typedef long long LL; const int MAXN = 1e5 + 10; const int MOD = 1e9 + 7; LL n, m, k, t;int main() { // freopen("test.in", "r", stdin);cin >> t;while (t--){cin >> n;int res = 0;bool flag = true;while (n != 1){if (n%2 == 0)n = n/2;else if (n%3 == 0)n = (n/3)*2;else if (n%5 == 0)n = (n/5)*4;else{flag = false;break;}res++;}if (flag)cout << res << endl;elsecout << -1 << endl;}return 0; }

轉載于:https://www.cnblogs.com/YDDDD/p/10998680.html

總結

以上是生活随笔為你收集整理的Codeforces Round #565 (Div. 3) A. Divide it!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。