- 3

Sum = 1 + 12 + 123 + 1234 + 12345 + … + 1234567891011…n how to sum%10007 mod answer

test input 2 output 13

19th Jul 2017, 12:12 PM
Ilyos Yuldoshev
Ilyos Yuldoshev - avatar
11 ответов
+ 4
thanks
6th Aug 2017, 6:01 PM
Ilyos Yuldoshev
Ilyos Yuldoshev - avatar
+ 4
You are welcome!
6th Aug 2017, 6:01 PM
Apoorva Shenoy Nayak
Apoorva Shenoy Nayak - avatar
+ 3
no input 3 output sum = 1+12+123=136%10007
28th Jul 2017, 3:49 AM
Ilyos Yuldoshev
Ilyos Yuldoshev - avatar
+ 1
import java.util.Scanner; public class Series  {  public static void main(String args[])   {   Scanner sc = new Scanner(System.in);   System.out.print("Enter the number of terms: ");   int n = sc.nextInt();   int s = 0, c;                       // s for terms of series, c for counter to generate n terms   for (c = 1; c <= n; c++) {    s = s * 10 + c;    System.out.print(s + " ");   }  } } Output: Enter the number of terms: 6 1,  12,  123,  1234,  12345,  123456....... You just need to add up!😸
19th Jul 2017, 7:26 AM
Apoorva Shenoy Nayak
Apoorva Shenoy Nayak - avatar
+ 1
Here you go. Sorry for the functions https://code.sololearn.com/cK6EYzD4k9ub/?ref=app
19th Jul 2017, 7:59 AM
Limitless
Limitless - avatar
+ 1
I'm confused, please elaborate
19th Jul 2017, 12:18 PM
Limitless
Limitless - avatar
19th Jul 2017, 12:28 PM
James
James - avatar
+ 1
Just add %10007 Easy! I'll update my code right away.
28th Jul 2017, 5:43 AM
James
James - avatar
+ 1
public class series { public static void main(String args[]) { int i,s=0; for(i=1;i<=9;i++) { s+=(s*10+1); } System.out.println("The sum of the series:"+s); } }
1st Aug 2019, 2:45 PM
Aniket Bhattacharjee
0
Can you say it in java that works on blue j
24th Oct 2021, 5:23 AM
Ayan Sunil
0
The general term satisfies the recurrence relation a(k) = 10a(k-1) + k with a(1) = 1. You can solve for it by back-substituting in the previous terms and you should get a(k) = (10^(k+1) - 9k - 10)/81. Summing from k = 1 to k = n gives you the result you need, s(n) = (100(100^n - 1))/729 - (n(n+1))/18 - (10n)/81. This is faster than calculating through a loop. Just ask for the input of n, plug it into the formula, and print the output of s(n).
21st Aug 2022, 4:28 PM
Michael David
Michael David - avatar