**New course!**Every coder should learn

**Generative AI!**

- 3

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

test input 2 output 13

11 Answers

+ 4

thanks

+ 4

You are welcome!

+ 3

no input 3 output sum = 1+12+123=136%10007

+ 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!😸

+ 1

Here you go.
Sorry for the functions
https://code.sololearn.com/cK6EYzD4k9ub/?ref=app

+ 1

I'm confused, please elaborate

+ 1

Here is JavaScript:
https://code.sololearn.com/Ws9P3r5Q2MvK/?ref=app

+ 1

Just add %10007
Easy!
I'll update my code right away.

+ 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);
}
}

0

Can you say it in java that works on blue j

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).