Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis- 3
Sum = 1 + 12 + 123 + 1234 + 12345 + ā¦ + 1234567891011ā¦n how to sum%10007 mod answer
test input 2 output 13
11 Respostas
+ 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).