Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1350 Accepted Submission(s): 634
Mike is so skillful that he can master n languages (aka. programming languages).
His nine friends are all weaker than he. The sets they can master are all subsets of Mike's languages.
But the relations between the nine friends is very complex. Here are some clues.
1. Alice is a nice girl, so her subset is a superset of Bob's.
2. Bob is a naughty boy, so his subset is a superset of Carol's.
3. Dave is a handsome boy, so his subset is a superset of Eve's.
4. Eve is an evil girl, so her subset is a superset of Frank's.
5. Gloria is a cute girl, so her subset is a superset of Henry's.
6. Henry is a tall boy, so his subset is a superset of Irene's.
7. Alice is a nice girl, so her subset is a superset of Eve's.
8. Eve is an evil girl, so her subset is a superset of Carol's.
9. Dave is a handsome boy, so his subset is a superset of Gloria's.
10. Gloria is a cute girl, so her subset is a superset of Frank's.
11. Gloria is a cute girl, so her subset is a superset of Bob's.
Now Mike wants to know, how many situations there might be.
For each test case, the first line contains an integer n(0≤n≤3000), denoting the number of languages.
0
2
Case #2: 1024
import java.util.*;
import java.math.*; public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger base = new BigInteger("32");
int t = sc.nextInt();
int n;
int cas = 0;
while (t-- > 0) {
n = sc.nextInt();
System.out.printf("Case #%d: ", ++cas);
System.out.println(base.pow(n));
}
}
}
用C++模拟也可以,
大数模板来一发,
/*
整数大数
int数组实现
*/
#include <bits/stdc++.h>
using namespace std; #define MAXN 9999//万进制
#define DLEN 4//4位 class BigNum{
//private:
public:
int a[];//可以控制大数位数(500*4)
int len;//大数长度
public:
BigNum(){//构造函数
len=;
memset(a,,sizeof(a));
}
BigNum(const int);//将int转化为大数
BigNum(const char *);//将字符串转化为大数
BigNum(const BigNum &);//拷贝构造函数
BigNum &operator=(const BigNum &);//重载赋值运算符,大数之间赋值 BigNum operator+(const BigNum &)const;//大数+大数
BigNum operator-(const BigNum &)const;//大数-大数
BigNum operator*(const BigNum &)const;//大数*大数
BigNum operator/(const int &)const;//大数/int BigNum operator^(const int &)const;//幂运算
int operator%(const int &)const;//取模
bool operator>(const BigNum &)const;//大数与大数比较
bool operator>(const int &)const;//大数与int比较 void print();//输出大数
}; BigNum::BigNum(const int b){//将int转化为大数
int c,d=b;
len=;
memset(a,,sizeof(a));
while(d>MAXN){
//c=d-(d/(MAXN+1))*(MAXN+1);
c=d%(MAXN+);//取出后四位
d=d/(MAXN+);//
a[len++]=c;
}
a[len++]=d;
}
BigNum::BigNum(const char *s){//将字符串转化为大数
int t,k,index,l,i,j;
memset(a,,sizeof(a));
l=strlen(s);
len=l/DLEN;
if(l%DLEN)++len;
index=;
for(i=l-;i>=;i-=DLEN){
t=;
k=i-DLEN+;
if(k<)k=;
for(j=k;j<=i;++j)
t=t*+s[j]-'';
a[index++]=t;
}
}
BigNum::BigNum(const BigNum &T):len(T.len){//拷贝构造函数
int i;
memset(a,,sizeof(a));
for(i=;i<len;++i)
a[i]=T.a[i];
}
BigNum &BigNum::operator=(const BigNum &n){//重载复制运算符,大数之间赋值
int i;
len=n.len;
memset(a,,sizeof(a));
for(i=;i<len;++i)
a[i]=n.a[i];
return *this;
} BigNum BigNum::operator+(const BigNum &T)const{//大数+大数
BigNum t(*this);
int i,big;//位数
big=T.len>len?T.len:len;
for(i=;i<big;++i){
t.a[i]+=T.a[i];
if(t.a[i]>MAXN){
++t.a[i+];
t.a[i]-=MAXN+;
}
}
if(t.a[big]!=)t.len=big+;
else t.len=big;
return t;
}
BigNum BigNum::operator-(const BigNum &T)const{//大数-大数
int i,j,big;
bool flag;
BigNum t1,t2;//t1大的,t2小的
if(*this>T){
t1=*this;
t2=T;
flag=;//前面的大
}
else{
t1=T;
t2=*this;
flag=;//前面的小
}
big=t1.len;
for(i=;i<big;++i){
if(t1.a[i]<t2.a[i]){
j=i+;
while(t1.a[j]==)++j;
--t1.a[j--];
while(j>i)t1.a[j--]+=MAXN;
t1.a[i]+=MAXN+-t2.a[i];
}
else t1.a[i]-=t2.a[i];
}
while(t1.a[t1.len-]==&&t1.len>){
--t1.len;
--big;
}
if(flag)t1.a[big-]=-t1.a[big-];//前面的小,结果为负
return t1;
}
BigNum BigNum::operator*(const BigNum &T)const{//大数*大数
BigNum ret;
int i,j,up;
int temp,temp1;
for(i=;i<len;++i){
up=;
for(j=;j<T.len;++j){
temp=a[i]*T.a[j]+ret.a[i+j]+up;
if(temp>MAXN){
//temp1=temp-temp/(MAXN+1)*(MAXN+1);
temp1=temp%(MAXN+);
up=temp/(MAXN+);
ret.a[i+j]=temp1;
}
else{
up=;
ret.a[i+j]=temp;
}
}
if(up!=)ret.a[i+j]=up;
}
ret.len=i+j;
while(ret.a[ret.len-]==&&ret.len>)--ret.len;
return ret;
}
BigNum BigNum::operator/(const int &b)const{//大数/int
BigNum ret;
int i,down=;
for(i=len-;i>=;--i){
ret.a[i]=(a[i]+down*(MAXN+))/b;
down=a[i]+down*(MAXN+)-ret.a[i]*b;
}
ret.len=len;
while(ret.a[ret.len-]==&&ret.len>)--ret.len;
return ret;
} BigNum BigNum::operator^(const int &n)const{//幂运算
BigNum t,ret();
int i;
if(n<)exit(-);
if(n==)return ;
if(n==)return *this;
int m=n;
while(m>){
t=*this;
for(i=;i<<<=m;i<<=){
t=t*t;
}
m-=i;
ret=ret*t;
if(m==)ret=ret*(*this);
}
return ret;
}
int BigNum::operator%(const int &b)const{//取模
int i,d=;
for(i=len-;i>=;--i){
d=((d*(MAXN+))%b+a[i])%b;
}
return d;
}
bool BigNum::operator>(const BigNum &T)const{//大数与大数比较
int ln;
if(len>T.len)return true;
else if(len==T.len){
ln=len-;
while(a[ln]==T.a[ln]&&ln>=)--ln;
if(ln>=&&a[ln]>T.a[ln])return true;
else return false;
}
else return false;
}
bool BigNum::operator>(const int &t)const{//大数与int比较
BigNum b(t);
return *this>b;
} void BigNum::print(){//输出大数
int i;
printf("%d",a[len-]);
for(i=len-;i>=;--i){
printf("%.4d",a[i]);//%.4d代表4位,不够前面补0
}
printf("\n");
} //int main(){
// char str1[]="2",str2[]="22222222222222222222222222222222222222222222";
// int c=2;
// //scanf("%s%s",str1,str2);
// BigNum a,b,t;
// a=BigNum(str1);
// b=BigNum(str2);
// printf("a=");a.print();
// printf("b=");b.print();
// printf("c=%d\n",c);
// printf("\n");
//
// t=a+b;
// printf("a+b=");t.print();
// t=a-b;
// printf("a-b=");t.print();
// t=a*b;
// printf("a*b=");t.print();
// t=a/c;
// printf("a/c=");t.print();
// printf("\n");
//
// t=a^c;
// printf("a^c=");t.print();
// t=a%c;
// printf("a%%c=");t.print();
//
// a>b?printf("a>b\n"):printf("a<=b\n");
// a>c?printf("a>c\n"):printf("a<=c\n");
//
// return 0;
//} int main()
{
// printf("%.4d\n", 4);
// printf("%04d\n", 4);
int t;
int n;
BigNum base = BigNum();
BigNum ans;
int cas = ;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
//printf("%d\n", (int)pow(32, n));
ans = base ^ n;
printf("Case #%d: ", ++cas);
ans.print();
//printf("len = %d\n", ans.len * 4);
}
return ;
}