MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / solve

Function solve

CodeChef_problems/Multiple of 3/solution.cpp:25–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 return 0;
24}
25void solve()
26{
27 long long int noOfDigits, first, second, sum=0, remaining, arr[4], temp;
28 cin>>noOfDigits>>first>>second;
29 sum+=first+second;
30 if((first+second)%5==0) //logic explained above
31 {
32 cout<<"NO\n";
33 }
34 else if((first+second)%2==0)
35 {
36 noOfDigits-=2; //as we have already added two digits sum in variable sum
37 sum+=(noOfDigits/4)*20; //as (2+4+6+8=20)
38 remaining=noOfDigits%4;
39 arr[0]=(first+second)%10;
40 arr[1]=(first+second+arr[0])%10;
41 arr[2]=(first+second+arr[0]+arr[1])%10;
42 arr[3]=(first+second+arr[0]+arr[1]+arr[2])%10;
43 for(int i=0;i<remaining;i++)
44 {
45 sum+=arr[i];
46 }
47 if(sum%3==0)
48 cout<<"YES\n";
49 else
50 cout<<"NO\n";
51 }
52 else
53 {
54 temp=first+second;
55 first=temp; //considering sum of first two digits as first digit
56 second=temp%10; //third digit
57 sum+=second;
58 noOfDigits-=3; //as we have already added two digits sum in variable sum
59 sum+=(noOfDigits/4)*20;//as (2+4+6+8=20)
60 remaining=noOfDigits%4;
61 arr[0]=(first+second)%10;
62 arr[1]=(first+second+arr[0])%10;
63 arr[2]=(first+second+arr[0]+arr[1])%10;
64 arr[3]=(first+second+arr[0]+arr[1]+arr[2])%10;
65 for(int i=0;i<remaining;i++)
66 {
67 sum+=arr[i];
68 }
69 if(sum%3==0)
70 cout<<"YES\n";
71 else
72 cout<<"NO\n";
73 }
74}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected