UVaLive 6844 - Combination

题意:输入一个low、high,求

这个题可以通过暴力小数据发现规律。对于一个数字n,如果这个数字的二进制有i个1,那么的值为2的i次方。然后用类似数位dp的方式统计结果。对于(1<<i),小于这个数有j个1的情况有C(i,j)个,对于每一个j先统计出有j位1的数字有多少个,然后计算结果。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned long long ll;
ll pw[100];
ll CCC(int u, int v) {
    ll ans = 1;
    for(ll i = 0; i < v; i++) {
        ans = ans * (u - i) / (i + 1);
    }
    return ans;
}
ll deal(ll n) {
    int x = 0;
    memset(pw, 0, sizeof(pw));
    for(int i = 63; i >= 0; i--) {
        ll t = 1LL << i;
        if((n & t) == 0) continue;
        ll m = 1;
        for(int j = 0; j <= i; j++) {
            pw[j + x] += m;
            m = m * (i - j) / (j + 1);
        }
        x++;
    }
    ll t = 1, ans = 0;
    for(int i = 0; i < 64; i++) {
        ans += t * pw[i];
        t *= 2;
    }
    return ans;
}
int main() {
    ll n, m;
    while(~scanf("%llu%llu", &n, &m) && (n || m)) {
        printf("%llu\n", deal(m + 1) - deal(n));
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Here's an example code snippet in Java to generate a unique 12 character alpha-numeric combination: ```java import java.security.SecureRandom; import java.util.Locale; import java.util.Objects; import java.util.Random; public class UniqueAlphaNumericGenerator { private static final String CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static final Random RANDOM = new SecureRandom(); public static String generateUniqueCode(int length) { Objects.requireNonNull(CHARSET, "charset is null"); if (length < 1) throw new IllegalArgumentException("length < 1: " + length); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; ++i) { sb.append(CHARSET.charAt(RANDOM.nextInt(CHARSET.length()))); } return sb.toString(); } public static void main(String[] args) { String uniqueCode = generateUniqueCode(12); System.out.println("Unique code: " + uniqueCode); } } ``` In this example, we define a charset consisting of digits and uppercase letters. We then use a `SecureRandom` instance to generate random indices into this charset, and append the corresponding characters to a `StringBuilder`. Finally, we return the resulting string as the unique code. The `generateUniqueCode` method takes an argument `length` to specify the length of the unique code to generate. Note that while this method generates a unique code with a very high probability, it is not guaranteed to be unique in all cases. If you need to ensure uniqueness in a distributed system, you may need to use additional techniques such as checking for collisions or using a unique identifier generator service.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值