問題B解答例
var test =100000;
var count = test-3;
var a = b = 0;
var c = 1;
function tribonacci(){
if(count < 0){
return 0;
}
while(count > 0){
var d = (a+b+c)%10007;
a = b;
b = c;
c = d;
count--;
}
return c;
}
console.log(tribonacci());
//a,b,c 10007で割った合計がdになるので結局最後に10007で割るのと同じ 桁あふれを起こさないために使⽤
10
解答例
var babies;
var adults;
varolds;
var rest;
var N = 7;
var M = 23;
function sphinx(){
if (N * 2 > M || N * 4 < M) {
console.log("-1 -1 -1");
} else {
rest = M - N * 2;
babies = Math.floor(rest / 2);
olds = rest % 2;
adults = N - olds - babies;
console.log("%d %d %d", adults, olds, babies);
}
}
sphinx();
19