I think you need to describe your problem more accurately in future @andriass. It needs to make sense mathematically and in English.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int sumDigits( int N ) { return N < 10 ? N : N % 10 + sumDigits( N / 10 ); }
int main()
{
int N;
cout << "How many terms do you want (>1)? "; cin >> N;
int term = 1;
cout << term;
for ( int i = 2; i <= N; i++ )
{
term = term + sumDigits( term );
cout << ", " << term;
}
}
How many terms do you want (>1)? 20
1, 2, 4, 8, 16, 23, 28, 38, 49, 62, 70, 77, 91, 101, 103, 107, 115, 122, 127, 137
Sorry i am bad in english and cant describe it very well.And i forget to write you have to calculate Sn, sum of An-s. I know you have to add Sn+=term, but problem is that N is big, N<10^17, since the prefix is large you have to output sn modulo 10e9+9.
I have examples for 123456789-An works correctly but Sn is wrong,
99004093. So what can i do? I used % but doesnt work.
Post your coding attempt in the forum, @andriass. Also try to provide a clearer mathematical explanation of the problem. I don't go for unknown external links and I don't use social networks. Please also give some examples.
There are formatting buttons on the right which allow you to use subscripts and superscripts. Your explanation might be easier to understand if you used them.
since the prefix is large you have to output sn modulo 10e9+9.