我正在解决这样一个问题,即对于范围(包括边界整数)之间的每个给定数字,我都要计算这些数字的修改值之和。例如,
x = 388,822,442
f(388,822,442)=3800200402
即将相同的数字设为零。 f(x)是修改值。
我遍历整数的每个数字,如果重复则将其设为零。
BufferedReader bf = new BufferedReader(newInputStreamReader(System.in));
String s[], s1[];
s = bf.readLine().trim().split("\\s+");
s1 = bf.readLine().trim().split("\\s+");
BigInteger sb = new BigInteger(s[1]);
BigInteger sb1 = new BigInteger(s1[1]);
BigInteger indexIncre = new BigInteger("1");
BigInteger first = new BigInteger(s[1]);
BigInteger last = new BigInteger(s1[1]);
BigInteger length = last.subtract(first);
BigInteger summation = new BigInteger("0");
for (index = new BigInteger("0"); !index.subtract(length).toString().equals("1");
index =index.add(indexIncre))
{
StringBuilder str = new StringBuilder(first.toString());
int len = str.length();
char c = str.charAt(0);
for (int i = 1; i < len; i++)
{
if (str.charAt(i) == c) {
str.setCharAt(i, '0');
} else
c = str.charAt(i);
}
first = first.add(indexIncre);
summation = summation.add(new BigInteger(str.toString()));
}
BigInteger modulo = BigInteger.valueOf((long) Math.pow(10, 9) + 7);
System.out.println(summation.mod(modulo));
例如 输入
1 8
2 12
输出
49
这是
的形式 输入
NL L
NR R
NL,L,NR,R的范围是
1≤NL,NR≤10^ 5
1≤L≤R<10 ^ 100,000
修改后的值为f(x)
f(8)=8,f(9)=9,f(10)=10,f(11)=10,f(12)=12
并对所有这些f(x) by 10^9+7