369 - Combinations
Moderator: Board moderators
In linux when you want to use the long long int, you only use it in function scanf and printf.
For example:
long long a;
scanf("%lli",&a);
printf("%lli",a);
If you want to use unsigned long long, then use scanf("%llu",&a);
unsigned long long is 64bits long. then you can store in it the value from 0 to 2^64-1.
Else long long usage is the same as any other integer type.
<font size=-1>[ This Message was edited by: ahanys on 2002-02-27 14:02 ]</font>
For example:
long long a;
scanf("%lli",&a);
printf("%lli",a);
If you want to use unsigned long long, then use scanf("%llu",&a);
unsigned long long is 64bits long. then you can store in it the value from 0 to 2^64-1.
Else long long usage is the same as any other integer type.
<font size=-1>[ This Message was edited by: ahanys on 2002-02-27 14:02 ]</font>
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
As far as I know, "int", "long int" and "long" are almost always the same. "long long" is better, but not supported by ANSI C++. Don't know about standard C++. Try this:
You could also try to find out what the Valladolid guys have with a small test program. If you do, let us know about the results...
Code: Select all
int main () {
cout << sizeof( unsigned int ) << endl;
cout << sizeof( unsigned long int ) << endl;
cout << sizeof( unsigned long ) << endl;
cout << sizeof( unsigned long long ) << endl;
}
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
-
- System administrator & Problemsetter
- Posts: 399
- Joined: Sat Jan 12, 2002 2:00 am
The Windows users can use 64 bit integer in the following way, and then before submitting to the OJ change it to long long
![:smile:](./images/smilies/icon_smile.gif)
#include<stdio.h>
__int64 test;
void main(void)
{
scanf("%I64d",&test);
printf("%I64dn",test);
}
<font size=-1>[ This Message was edited by: shahriar_manzoor on 2002-03-22 09:53 ]</font>
<font size=-1>[ This Message was edited by: shahriar_manzoor on 2002-03-22 09:54 ]</font>
![:smile:](./images/smilies/icon_smile.gif)
#include<stdio.h>
__int64 test;
void main(void)
{
scanf("%I64d",&test);
printf("%I64dn",test);
}
<font size=-1>[ This Message was edited by: shahriar_manzoor on 2002-03-22 09:53 ]</font>
<font size=-1>[ This Message was edited by: shahriar_manzoor on 2002-03-22 09:54 ]</font>
369 - Combinations
i solved it but i got WA many times
i can't find the wrong..
help me!!
thanks!!
(problem 369)
(i use TurboC++ 3)
-------------------------
#include "stdio.h"
void main()
{
unsigned long n,m,c;
while(scanf("%lu %lu",&n,&m)==2){
unsigned long i,j; long double cc=1;
if(n==0&&m==0)break;
if(n-m<m) m=n-m;
for(i=n,j=(unsigned long)1;j<=m;i--&&j++)
{
cc *=(long double)i;
cc /=(long double)j;
}
c=(unsigned long)cc;
printf("%lu things taken %lu at a time is %lu exactly.\n",n,m,c);
}
}
i can't find the wrong..
![:cry:](./images/smilies/icon_cry.gif)
help me!!
thanks!!
(problem 369)
(i use TurboC++ 3)
-------------------------
#include "stdio.h"
void main()
{
unsigned long n,m,c;
while(scanf("%lu %lu",&n,&m)==2){
unsigned long i,j; long double cc=1;
if(n==0&&m==0)break;
if(n-m<m) m=n-m;
for(i=n,j=(unsigned long)1;j<=m;i--&&j++)
{
cc *=(long double)i;
cc /=(long double)j;
}
c=(unsigned long)cc;
printf("%lu things taken %lu at a time is %lu exactly.\n",n,m,c);
}
}
Ok, people, there's something REALLY wrong about this problem. I tried tons of different approaches, and I got more W.A.'s than I can remember. But, for each one of them, I couldn't find one single test case for which my solution was wrong.
Anyway, my last desperate attempt was to use a Big Integer data type to calculate. So I did. The main part of the program appears below:
...
void main()
{
int n, m, M, i;
TBigNumber *c = (TBigNumber *) malloc (sizeof(TBigNumber));
TBigNumber *aux = (TBigNumber *) malloc (sizeof(TBigNumber));
scanf("%d %d", &n, &M);
while (n)
{
m = (M > n / 2) ? n - M : M;
InitNumber(c, 1); /* initializes c with "1" */
for (i = 1; i <= m; i++)
{
InitNumber(aux, n - i + 1);
BigMul(c, aux, c); /* multiplies c and aux, result in c */
}
for (i = 1; i < m; i++)
{
InitNumber(aux, m - i + 1);
BigDivMod(c, aux, c, aux); /* divides c by aux, result in c, remainder in aux */
}
printf("%d things taken %d at a time is ", n, M);
for (i = 0; i < c->Size; i++)
printf("%d", c->Digits);
printf(" exactly.\n");
scanf("%d %d", &n, &M);
}
free(c);
free(aux);
}
...
In this last version, I didn't use any trick - it was straight from the formula. It just CAN'T be wrong, I've used this same Big Integer structure lots of times, it is 100% correct. Is there anyone who got "accepted" in this problem and would be willing to send me a text file in the form
<value of N> <value of M> <right answer>
so I can check my program one last time before shooting my computer?
Thanks in advance,
Rodrigo
PS: I won't use your file to create a huge look-up array
, I just wanna know what's wrong.
![:cry:](./images/smilies/icon_cry.gif)
Anyway, my last desperate attempt was to use a Big Integer data type to calculate. So I did. The main part of the program appears below:
...
void main()
{
int n, m, M, i;
TBigNumber *c = (TBigNumber *) malloc (sizeof(TBigNumber));
TBigNumber *aux = (TBigNumber *) malloc (sizeof(TBigNumber));
scanf("%d %d", &n, &M);
while (n)
{
m = (M > n / 2) ? n - M : M;
InitNumber(c, 1); /* initializes c with "1" */
for (i = 1; i <= m; i++)
{
InitNumber(aux, n - i + 1);
BigMul(c, aux, c); /* multiplies c and aux, result in c */
}
for (i = 1; i < m; i++)
{
InitNumber(aux, m - i + 1);
BigDivMod(c, aux, c, aux); /* divides c by aux, result in c, remainder in aux */
}
printf("%d things taken %d at a time is ", n, M);
for (i = 0; i < c->Size; i++)
printf("%d", c->Digits);
printf(" exactly.\n");
scanf("%d %d", &n, &M);
}
free(c);
free(aux);
}
...
In this last version, I didn't use any trick - it was straight from the formula. It just CAN'T be wrong, I've used this same Big Integer structure lots of times, it is 100% correct. Is there anyone who got "accepted" in this problem and would be willing to send me a text file in the form
<value of N> <value of M> <right answer>
so I can check my program one last time before shooting my computer?
Thanks in advance,
Rodrigo
PS: I won't use your file to create a huge look-up array
![:)](./images/smilies/icon_smile.gif)