help~!

hello everyone, im stuck in this question:

For example, 10002 is the first 5-digit number that is divisible by by 3. And 10005 is the second 5-digit number that is divisible by by 3. Write a program that finds kth n-digit number which is divisible by m.

Anyone can help me?
need it in c++
what do you have so far. I can tell you that for n-digit number get the user input and multiply 1x10^(n-1) where n is the user input. That will put you at whatever digit number you need. Get the user input for both m and k as well. Then just create a counter equal to k, and mod the number by m reducing k each time m == 0.
Last edited on
In short this is what you are looking for: you can format it yourself lol.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;

int main()
{
	int n,k,m;

	cout << "n: ";
	cin >> n;

	n = 1*pow(10.0, n-1);

	cout << "k: ";
	cin >> k;

	cout << "m: ";
	cin >> m;

	while (k != 0)
	{
		if ((n%m) == 0)
		{
			k--;
		}
		n++;
	}
	n--;

	cout << n << endl << endl;

	return 0;
}
it says wrong answer even though the program works, i think its because:

Note: The question says that the number can be up to 30 digits.

You cannot keep 30 digit number in integers. You should use array to store every digit of the number. Then you process the array as your number.
lol bro its your assignment, you never said 30 digits, and its super easy to modify for only 30 digits.
How????
Well if you cant figure that out by yourself I highly recommend you choose a new profession, but I will help you out and show you what to do http://lmgtfy.com/?q=c%2B%2B+storing+large+numbers
Last edited on
Topic archived. No new replies allowed.