Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- const int MOD = 1000000007;
- int calc(int a[], int lvl, int num)
- {
- long long int d;
- int i=0;
- double newa[num];
- while(i<num)
- {
- newa[i]=log(a[i]);
- i++;
- }
- while(num)
- {
- if(newa[num-1]>=newa[num-2])
- {
- d*=(a[num-1]%MOD);
- newa[num/2]+=newa[num-1];
- num=num-2;
- }
- else
- {
- d*=(a[num-2]%MOD);
- newa[num/2]+=newa[num-1];
- num=num-2;
- }
- }
- return d;
- }
- int main()
- {
- int d =1;
- while(d)
- {
- scanf("%d",&d);
- int els;
- els = (1<<d)-1;
- long long int val;
- //printf("%d\n",els);
- int i=0;
- int arr[els];
- while(i<els)
- {
- scanf("%d",&arr[i]);
- i++;
- }
- /* i=0;
- while(i<els)
- {
- printf("%d",arr[i]);
- ++i;
- }*/
- val = calc(arr,d,els);
- printf("%lld",val);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment