-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply_basic_maths.js
76 lines (70 loc) · 1.63 KB
/
apply_basic_maths.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function runProgram(input){
var input_arr = input.trim().split(/[\r\n]+/)
var array = input_arr[1].split(" ")
var sum = 0
for( var i = 0; i < array.length; i++)
{
array[i] = Number(array[i])
sum += array[i]
}
if(sum%7 == 0)
{
var flag = false
for(var i = 7; i < Infinity; i=i+7)
{
for(var j = 0; j < array.length; j++ )
{
if(array[j] == i)
{
console.log(j)
flag = true
break;
}
}
if(flag)
{
break;
}
}
}
else if(sum%7 != 0)
{
var remainder = sum%7
var flag = false
for(var i = remainder; i < 100000; i=i+7)
{
for(var j = 0; j < array.length; j++)
{
if(array[j] == i)
{
console.log(j)
flag = true
break;
}
}
if(flag)
{
break;
}
}
if(!flag)
{
console.log(-1)
}
}
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
let read = "";
process.stdin.on("data", function (input) {
read += input;
});
process.stdin.on("end", function () {
read = read.replace(/\n$/,"")
runProgram(read);
});
process.on("SIGINT", function () {
read = read.replace(/\n$/,"")
runProgram(read);
process.exit(0);
});