-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivisible by 4.cpp
49 lines (34 loc) · 929 Bytes
/
divisible by 4.cpp
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
///very big number is divisible by 4 or not
/// complexity O(n)
#include<bits/stdc++.h>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
//sync;
string s; cin>>s;
int l = s.size();
int last = s[l-1]-'0';
if(l==1 && last%4==0) cout<< "Yes divisible\n";
else {
int second_last = s[l-2]-'0';
int num = second_last*10+last;
if(num%4==0) cout<< "Yes divisible \n";
else cout<< "Not divisible\n";
}
///using substring,stoi function
string p,q;
cin>>p;
int l1 = p.size();
int sesh = p[l1-1]-'0';
if(l1==1 && sesh%4==0) cout<< "Yes\n";
else{
p = p.substr(l1-3,2);
//cout<< p << endl;
int q = stoi(p);
if(q%4==0) cout<< "Yes\n";
else cout<< "No\n";
}
return 0;
}