Codeforces Round #400 Molly's Chemicals 前缀和

本文介绍了Codeforces Round #400中的一道题目,Molly想要通过混合化学品来制作爱情药水,其中化学品的吸引力值之和需要为k的非负整数次幂。文章详细解析了解题思路,包括如何使用前缀和技巧,并提供了两种不同情况(k为1和-1)下的解决方案。同时,还展示了错误的枚举方法并解释了其问题所在,最后给出了高效的解题代码。
摘要由CSDN通过智能技术生成

题目:

C. Molly's Chemicals
time limit per test
2.5 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.

Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power ofk. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.

Help her to do so in finding the total number of such segments.

Input

The first line of input contains two integers, n and k, the number of chemicals and th

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值