-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNITT2.cpp
More file actions
72 lines (55 loc) · 1.43 KB
/
NITT2.cpp
File metadata and controls
72 lines (55 loc) · 1.43 KB
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
#include <stdio.h>
#include <string.h>
#include <utility>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int nitt2()
{
int test_cases;
scanf("%d", &test_cases);
while(test_cases--)
{
char digits[50001] = {0};
scanf("%s", digits);
// look for length
int len = strlen(digits);
int sum_of_digits = 0;
for(int k = 0; k < len; k++)
{
digits[k] -= '0';
sum_of_digits += digits[k];
}
if(len <= 2 || (len == 3 && (digits[0]*100 + digits[1]*10 + digits[2] < 252)))
{
printf("No No\r\n");
continue;
}
// 2^2 * 3^2 * 7 == 252
// 3 * 5^2 * 7 == 525
// we need to test if number is divideable by them all!
// let's start with 2^2,
// well basically number is divideable by 4, if last two digits are!
int last_two_digits = digits[len - 2]*10 + digits[len-1];
// is number divideable by 7?
int nr[] = {1, 3, 2, 6, 4, 5};
int count = 6;
int exc = 0;
int ben = 0;
for(int j = len - 1; j >= 0; j--)
{
exc += digits[j] * nr[ben % count];
ben++;
}
int is_divisable_by_seven = exc % 7 == 0;
int r_252 = false;
int r_525 = false;
// check out if it's dividable by 252
if(last_two_digits % 4 == 0 && sum_of_digits % 9 == 0 && is_divisable_by_seven) r_252 = true;
if(sum_of_digits % 3 == 0 && is_divisable_by_seven && last_two_digits % 25 == 0) r_525 = true;
printf("%s %s\r\n", r_252 ? "Yes" : "No", r_525 ? "Yes" : "No");
}
return 0;
}