Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Bài 2. Bội số chỉ chứa 0 và 9
- Cho số tự nhiên N. Hãy tìm số nguyên dương X nhỏ nhất được tạo bởi số 9 và số 0 chia hết cho N. Ví dụ với N = 5 ta sẽ tìm ra X = 90.
- Input:
- Dòng đầu tiên ghi lại số lượng test T (T≤100).
- Những dòng kế tiếp mỗi dòng ghi lại một test. Mỗi test là một số tự nhiên N được ghi trên một dòng (N≤100).
- Output:
- Đưa ra theo từng dòng số X nhỏ nhất chia hết cho N tìm được .
- Ví dụ:
- Input
- Output
- 2
- 5
- 7
- 90
- 9009 */
- #include<bits/stdc++.h>
- using namespace std;
- #define pub push_back
- #define ll long long
- string s[10001];
- int findThisNumber (int n){
- queue < string > q;
- q.push ("9");
- while (1){
- string getFront = q.front ();
- q.pop();
- int current = stoi (getFront);
- if ( current % n == 0 ){
- return current ;
- }
- string first = getFront + "0";
- string second = getFront + "9";
- q.push(first );
- q.push(second);
- }
- }
- int main(){
- int t;
- cin >> t;
- while ( t-- ){
- int n;
- cin >> n;
- cout << findThisNumber(n) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment