Created
November 8, 2012 05:33
-
-
Save adis-io/4037020 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <iostream> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| #define MAX 50 | |
| #define BILL 1000*1000*1000 | |
| using namespace std; | |
| void nullArr (int *a) { | |
| for (int i=0; i<MAX; i++) { | |
| a[i]=0; | |
| } | |
| } | |
| void i2long(int num, int *a) { | |
| nullArr(a); | |
| int i=0; | |
| while(num) { | |
| i+=1; | |
| a[i]= num % 10; | |
| num = num / 10; | |
| } | |
| a[0]=i; | |
| } | |
| int complong(int *a, int *b) { | |
| if (a[0] < b[0]) return -1; | |
| if (a[0] > b[0]) return 1; | |
| for(int i=a[0]; i>=1; i--) { | |
| if (a[i] < b[i]) return -1; | |
| if (a[i] > b[i]) return 1; | |
| } | |
| return 0; | |
| } | |
| void mul(int *a, int b) { | |
| int c=0; | |
| for(int i=1; i<=a[0]; i++) { | |
| a[i] = a[i]*b+c; | |
| c = a[i] / 10; | |
| a[i] = a[i] % 10; | |
| } | |
| while(c > 0) { | |
| a[0] = a[0]+1; | |
| a[a[0]] = c % 10; | |
| c = c / 10; | |
| } | |
| } | |
| int mullong(int *a, int *b, int *c) { | |
| nullArr(c); | |
| int cr,k; | |
| if (b[0]==1 && b[1]==0) { | |
| c[0]=1; | |
| return 0; | |
| } | |
| for(int i=1; i<=a[0]; i++) { | |
| for(int j=1; j<=b[0]; j++) { | |
| cr = a[i]*b[j]; | |
| k = i+j-1; | |
| while(cr>0) { | |
| cr = cr+c[k]; | |
| c[k] = cr % 10; | |
| cr = cr / 10; | |
| k > c[0]&&(c[0]=k); | |
| k +=1; | |
| } | |
| } | |
| } | |
| return 0; | |
| } | |
| void pow2(int P, int *a) { | |
| nullArr(a); | |
| a[0]=1; | |
| a[1]=1; | |
| if (P) | |
| for (unsigned int i=0; i<P; i++) { | |
| mul(a,2); | |
| } | |
| } | |
| void writelong(int *a) { | |
| for(int i=a[0]; i>=1; i--) { | |
| cout << a[i]; | |
| } | |
| } | |
| void sublong(int *a, int *b) { | |
| int c=0; | |
| for(int i=1; i<=a[0]; i++) { | |
| c = c+a[i]-b[i]+10; | |
| a[i] = c % 10; | |
| c = c < 10?-1:0; | |
| } | |
| } | |
| int asd(long a) { | |
| if (a % 8==0 || a==0) | |
| return 3; | |
| if (a % 4==0) | |
| return 2; | |
| if (a % 2==0) | |
| return 1; | |
| return 0; | |
| } | |
| void mas_rec(int n, long *arr, int *mar) { | |
| int i; | |
| for (i=0; i<n; i++) { | |
| arr[i]=asd(arr[i]); | |
| }; | |
| for (i=0; i<4; i++) | |
| mar[i]=0; | |
| for (i=0; i<n; i++) | |
| mar[arr[i]]+=1; | |
| } | |
| int main(void) { | |
| int a[MAX],b[MAX], c[MAX], t; | |
| nullArr(a); | |
| nullArr(b); | |
| nullArr(c); | |
| long arr[100]; | |
| int mar[4],m,m1; | |
| long res; | |
| unsigned long i,n=0; | |
| cin >> n; | |
| for (i=0; i<n; i++) | |
| cin >> arr[i]; | |
| mas_rec(n, arr, mar); | |
| m = (1 + (mar[1]+1)*mar[1]/2 + mar[2]); | |
| i2long(m,c); | |
| pow2(n-mar[0],b); | |
| sublong(b, c); | |
| pow2(mar[0],a); | |
| mullong(a,b,c); | |
| i2long(BILL,a); | |
| if (complong(c,a)==1) | |
| cout << "too many eights"; | |
| else | |
| writelong(c); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment