# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
4301 | zorrapower | Inherited disease (kriii1_I) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
void get_N_generationArea(unsigned long n,unsigned long *start, unsigned long *end);
unsigned long Factorial(unsigned long n);
unsigned long getResult(unsigned long n, unsigned long *start, unsigned long *end);
unsigned long Array[100];
unsigned long n;
unsigned long main(void){
unsigned long start,end;
get_N_generationArea(2, &start, &end);
scanf("%d", &n);
for(unsigned long i=0; i<n; i++)
scanf("%d", &Array[i]);
for(unsigned long i=1; i<=n; i++){
printf("%d\n", getResult(i, &start, &end)%1000000007);
}
return 0;
}
void get_N_generationArea(unsigned long n,unsigned long *start, unsigned long *end){
*start=0;
*end=0;
for(unsigned long i=1; i<=n; i++){
*end+=Factorial(i);
*start=*end-Factorial(i)+1;
}
}
unsigned long Factorial(unsigned long n){
unsigned long result=1;
for(unsigned long i=1; i<=n; i++)
result*=i;
return result;
}
unsigned long getResult(unsigned long generation, unsigned long *start, unsigned long *end){
unsigned long area;
get_N_generationArea(generation, start, end);
area=*end-*start+1;
for(unsigned long i=0; i<generation; i++){
area/=i+1;
*start+=area*(Array[i]-1);
*end=*start+area-1;
}
return *start;
}