Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdio>
- using namespace std;
- long long k; ///finding the least multiple of this number
- int divisibility(string n, int l)
- {
- long long a;
- a = 0;
- for(int i = 0; i < l; i++){
- a = a*10 + (n[i] - '0');
- a = a % k;
- }
- return !a; ///return 1 if a == 0, return 0 if a != 0
- }
- int main()
- {
- int i, l, n3, n0, j, ind_of_3;
- string num;
- while(scanf("%lld", &k) == 1){
- num.push_back('3');
- n3 = 1; ///number of 3s
- n0 = 0; ///number of 0s
- l = 1; ///length of number
- ind_of_3 = 0; ///index of last 3
- while(1){
- if(divisibility(num, l)){
- printf("%d %d %d\n", l, n3, n0);
- break;
- }
- if(l == n3){
- num.push_back('0');
- l++;
- n0++;
- j = l-1;
- for(i = 1; i < j; i++){
- num[i] = '0';
- n0++;
- n3--;
- }
- ind_of_3 = 0;
- }
- else{
- ind_of_3++;
- num[ind_of_3] = '3';
- n3++;
- n0--;
- }
- }
- num.erase(num.begin(), num.end());
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement