Problem 20

问题描述:
n! means n (n 1) ... 3 2 1
For example, 10! = 10 9 ... 3 2 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!


Java中可以使用BigDecimal
不过也可以使用自己实现的大数算法~

结果:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 6 8 6 1 9 0 1 2 5 8 1 1 5 2 8 5 7 3 2 2 7 2 8 0 2 9 7 9 6 3 5 2 6 8 2 8 1 5 6 5 1 6 7 9 3 6 4 1 4 9 8 0 6 5 1 9 9 2 2 3 9 9 9 9 5 7 1 2 5 9 8 3 6 9 2 9 5 8 6 4 1 2 6 1 8 3 4 6 2 8 6 9 5 1 7 0 9 4 0 0 7 6 6 2 6 5 8 8 3 2 9 9 6 1 8 6 2 5 1 4 4 9 3 4 4 5 1 2 6 2 3 3 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
648
16
最后的16是执行的时间毫秒级别
因为每次都会产生无用的0,而且越来越多,导致进行无效的计算很多次
算法还可以改进~

具体的算法
public static Byte[] StringToByte(String number){
int len = number.length();
Byte[] result = new Byte[len];
//从高位到低位依次转换,转换后字符串"1234"变为4321,这样方便以后计算
for(int i=0; i<number.length(); i++){
byte curByte = Integer.valueOf(number.charAt(i)+"").byteValue();
result[len-i-1] = curByte;
}

return result;
}

public static Byte[] Add(Byte[] number1, Byte[] number2){
int len = (number1.length>number2.length) ? number1.length : number2.length;
Byte[] result = new Byte[len+1];
Integer sum = new Integer(0);
Integer carry = new Integer(0);
int i;
if(number1.length>number2.length){
for(i=0; i<number2.length; i++){
sum = number1[i].intValue() + number2[i].intValue();
sum = sum +carry;
carry = ((sum -10)>=0) ? 1:0;
sum = ((sum -10)>=0) ? (sum-10):sum;
result[i] = sum.byteValue();
sum = 0;
}
for(;i<number1.length;i++){
sum = number1[i] +carry;
carry = ((sum -10)>=0) ? 1:0;
sum = ((sum -10)>=0) ? (sum-10):sum;
result[i] = sum.byteValue();
sum = 0;
}
if(carry!=0){
result[i] = carry.byteValue();
}else{
result[i] = 0;
}
}else{
for(i=0; i<number1.length; i++){
sum = number1[i].intValue() + number2[i].intValue();
sum = sum +carry;
carry = ((sum -10)>=0) ? 1:0;
sum = ((sum -10)>=0) ? (sum-10):sum;
result[i] = sum.byteValue();
sum = 0;
}
for(;i<number2.length;i++){
sum = number2[i].intValue() + carry;
carry = ((sum -10)>=0) ? 1:0;
sum = ((sum -10)>=0) ? (sum-10):sum;
result[i] = sum.byteValue();
sum = 0;
}
if(carry!=0){
result[i] = carry.byteValue();
}else{
result[i] = 0;
}
}

return result;
}
//level表示左移次数
public static Byte[] left_shift(Byte[] number, int level){
Byte[] result = new Byte[number.length+level];
Integer zero = 0;
for(int i=0; i<level; i++){
result[i] = zero.byteValue();
}
for(int i=0; i<number.length; i++){
result[i+level] = number[i];
}
return result;
}

//乘法计算过程中被乘数总是与成数的一位相乘
public static Byte[] MultiplyOne(Byte[] number1, Byte number2){
Byte[] result = new Byte[number1.length+1];
Integer cur = 0;
Integer carry = 0;
Integer zero = 0;
int i;
Arrays.fill(result, zero.byteValue());

for(i=0; i<number1.length; i++){
cur = number1[i].intValue()*number2.byteValue();
cur = cur +carry;
carry = cur/10;
cur = cur%10;
result[i] = cur.byteValue();
cur = 0;
}
if(carry==0){
result[i] = cur.byteValue();
}else{
result[i] = carry.byteValue();
}

return result;
}

public static Byte[] Multiply(Byte[] number1, Byte[] number2){
Byte[] result = new Byte[number1.length+1];
Byte[] before = new Byte[number1.length];
Integer zero = 0;
Arrays.fill(before, zero.byteValue());

for(int i=0; i<number2.length; i++){
result = MultiplyOne(number1, number2[i]);
result = left_shift(result, i);
result = Add(result, before);
before = result;

}

return result ;
}

public static void print(Byte[] result){
for(int i=0; i<result.length; i++){
System.out.print(result[i]+" ");
}
System.out.println();
}


public static void main(String[] args){
Integer one = 1;
Byte[] result = new Byte[1];
result[0] = one.byteValue();
long t1 = System.currentTimeMillis();
for(Integer i=2; i<=100; i++){
Byte[] cur = BigNumber.BigNumber.StringToByte(i+"");
result = BigNumber.BigNumber.Multiply(result, cur);
}
int sum = 0;
for(int i=0; i<result.length; i++){
sum += result[i].intValue();
}
long t2 = System.currentTimeMillis();
BigNumber.BigNumber.print(result);
System.out.println(sum);
System.out.println((t2-t1));
}
<think>好的,用户现在想了解如何在Zabbix 6.0中查询问题(problem)。我需要结合之前的对话和提供的引用内容来给出准确的回答。 首先,回顾用户之前的问题,他们询问了分页查询的方法,我给出了使用API的limit和page参数,以及相关的示例。现在用户的问题转向了查询问题(problem),这可能涉及到Zabbix的前端界面和API两种方式。 查看用户提供的引用内容,引用[3]提到了安装zabbix前端,使用docker部署了web界面。这可能意味着用户对前端操作有一定需求。引用[4]提到了Zabbix agent的术语,但可能与问题查询关系不大。引用[5]是关于报警设置的,可能不直接相关,但说明用户可能对通知机制感兴趣,而问题查询可能与报警有关联。 用户可能需要知道如何在前端查看当前的问题,比如触发器触发的告警,或者通过API获取问题列表。需要确认Zabbix 6.0中问题的查询方法是否有变化,或者是否有特定的参数需要注意。 在前端部分,通常问题会显示在“Monitoring”->“Problems”页面,用户可能需要过滤条件,比如时间范围、主机组、严重性等。在API方面,使用problem.get方法,可能需要指定输出字段、时间范围等参数。 另外,用户之前的分页查询使用了limit和page参数,可能在API查询问题时也需要分页,所以应该在回答中提到这些参数的使用,保持一致性。同时,引用[1]和[2]是关于服务重启和数据库配置的,可能与当前问题无关,但需要确保回答的准确性,避免冲突。 需要验证Zabbix 6.0的API文档,确认problem.get的参数是否支持limit和page,或者是否需要使用其他分页方法。例如,是否需要计算offset,或者是否可以直接使用page参数。 此外,用户可能需要知道如何通过时间戳过滤最近的问题,或者如何关联触发器、主机等信息,因此需要给出相应的示例,包括参数如selectTriggers和selectHosts。 总结回答的结构,分前端和API两部分,每个部分给出步骤和示例,注意事项中提及分页和过滤,最后附上相关问题。确保引用正确的文献,比如Zabbix官方文档作为参考。</think>在Zabbix 6.0中,查询问题(Problems)可通过**Web界面操作**和**API调用**两种方式实现,以下是具体方法和示例: --- ### 一、Web界面查询方法 1. **路径导航** 登录Zabbix控制台 → 左侧菜单栏选择 `Monitoring` → `Problems` ![问题列表界面示意图](https://www.zabbix.com/documentation/6.0/_media/manual/web_interface/problems_view.png) 2. **筛选条件设置** - **时间范围**:右上角时间选择器设置查询时段(如最近1小时) - **过滤器**:支持按主机组、触发器名称、严重性等级(如`High`/`Disaster`)过滤 - **显示列**:可自定义显示字段(如`Host`/`Problem`/`Severity`/`Duration`) 3. **排序与标记** - 点击表头按字段排序(如按持续时间倒序) - 勾选问题后可批量标记为已解决(`Acknowledge`)[^4] --- ### 二、API查询方法 使用`problem.get`接口,核心参数如下: ```json { "jsonrpc": "2.0", "method": "problem.get", "params": { "output": ["eventid", "name", "severity", "acknowledged", "opdata"], "selectTriggers": ["description", "priority"], // 关联触发器详情 "selectHosts": ["hostid", "host"], // 关联主机信息 "time_from": "1659283200", // 起始时间戳(Unix格式) "time_till": "1659369600", // 结束时间戳 "sortfield": ["eventid"], // 排序字段 "limit": 20 // 分页参数 }, "auth": "YOUR_AUTH_TOKEN", "id": 1 } ``` #### 典型场景示例 1. **查询未确认的高优先级问题** ```json "filter": { "acknowledged": 0, // 0表示未确认 "severity": 5 // Disaster级(数值对应严重性等级) } ``` 2. **分页查询** 结合`limit`和`page`参数(或手动计算`offset`)实现分页加载[^1]: ```json "params": { "limit": 50, "page": 3 } ``` --- ### 三、注意事项 1. **时间戳转换**:Web界面时间范围需转换为Unix时间戳(可通过[在线工具](https://www.epochconverter.com/)处理) 2. **性能优化**:大数据量查询建议添加`time_from`/`time_till`限制时间范围 3. **关联数据**:通过`select*`参数可扩展查询关联对象(如触发器、主机、事件) ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值