c++#include <iostream>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int N;
cin >> N;
int res = 0;
for (int i = 1; i <= N; i++) {
int num = i;
while (num % 10 == 0) {
num /= 10;
res += num;
res %= MOD;
}
cout << res << endl;
return 0;
}JAVAimport java.util.Scanner;
public class Main {
public static final int MOD = 1_000_000_007;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
System.out.println(res);
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
c++
#include <iostream>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int N;
cin >> N;
int res = 0;
for (int i = 1; i <= N; i++) {
int num = i;
while (num % 10 == 0) {
num /= 10;
res += num;
res %= MOD;
}
}
cout << res << endl;
return 0;
}
JAVA
import java.util.Scanner;
public class Main {
public static final int MOD = 1_000_000_007;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int res = 0;
for (int i = 1; i <= N; i++) {
int num = i;
while (num % 10 == 0) {
num /= 10;
res += num;
res %= MOD;
}
}
System.out.println(res);
}
}