BUILDING PROGRAM

May 29, 2018 at 6:36am
given sequence 1 2 4 8 16 23 ...
so An+1=An+suM of An;
and how to write program wich calculate An element.
i wrote but it need Much time.
Last edited on May 29, 2018 at 6:36am
May 29, 2018 at 6:36am
An+1=An+sum of An numbers
May 29, 2018 at 8:00am
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>
using namespace 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
Last edited on May 29, 2018 at 4:15pm
May 29, 2018 at 3:33pm
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.
May 29, 2018 at 3:34pm
If you have mail or any social network i can send you tasks picture. Its in english.
May 29, 2018 at 3:39pm
May 29, 2018 at 4:09pm
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.

What?
Last edited on May 29, 2018 at 4:19pm
May 29, 2018 at 4:12pm
See image on my google drive.
May 29, 2018 at 4:20pm
Please just write the problem out carefully.

AND SHOW YOUR ATTEMPT - you are getting a lot of free code.
May 29, 2018 at 4:40pm
So have sequence 1 2 4 8 16 23.
in program we input T integer, T<32768, indicating the total number of test cases. And then we input integer n<1017
for each test case output an and sn. SINCE the prefix sum is large, you only need output sn
modulo 109+9. However you should output an
exact value
.

Exm. 
6                    23 -54
66                  752-20862
123456789 5061289531-990040993
May 29, 2018 at 4:41pm
time limit:3s
Memory limit:512mb
May 29, 2018 at 5:57pm
You STILL haven't defined your actual sequence in an intelligible manner - there are several sequences that could start like that.

Define an and sn carefully and intelligibly.

You STILL haven't shown us your own code.

I have no idea what your examples mean, as you appear to have got negative numbers from somewhere.

Are you sure you don't want sn modulo 9 rather than modulo 109+9?
Last edited on May 29, 2018 at 8:22pm
Topic archived. No new replies allowed.