# UVa 12208 how Many ones Needed? (Combinatorial mathematics)

Source: Internet
Author: User
Tags cas time limit

12208-how Many ones Needed?

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=244&page=show_ problem&problem=3360

Water.

Complete code:

```/*0.035s*/

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

ll c[31][31], sum;
int I, j, CNT;

void init ()
{for
(i = 0; i < ++i)
c[i][0] = c[i][i] = 1;
for (i = 2; i < n ++i) for
(j = 1; j < i; ++j)
c[i][j] = c[i-1][j-1] + c[i-1][j];
}

inline ll Calc (int n, bool yeah)
{
sum = CNT = 0;
for (i = to i >= 0;-i)
{
if (n & (1 << i))
{for
(j = 0; J <= i; ++j)
sum = C I [j] * (j + CNT);
++cnt
}
}
if (yeah) sum + = cnt;///The number n is also counted as return
sum;
}

int main ()
{
init ();
int A, b, cas = 0;
ll ans;
while (scanf ("%d%d", &a, &b), a | | b)
printf ("Case%d:%lld\n", ++cas, Calc (b, True)-Calc (A, false));
return 0;
}```

Author: csdn Blog Synapse7

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.