text: Check if a number S can be made divisible by D by repeatedly adding the remainder to S | C # program for the above approach ; Function to check if S is divisible by D while changing S to ( S + S % D ) ; V ( 0 ) = S % D ; Stores the encountered values ; V ( i ) = ( V ( i - 1 ) + V ( i - 1 ) % D ) % D ; Check if the value has already been encountered ; Edge Case ; Otherwise , insert it into the hashmap ; Driver Code
code: using System ; using System . Linq ; using System . Collections . Generic ; class GFG { static string isDivisibleByDivisor ( int S , int D ) { S %= D ; List < int > hashMap = new List < int > ( ) ; ; hashMap . Add ( S ) ; for ( int i = 0 ; i <= D ; i ++ ) { S += ( S % D ) ; S %= D ; if ( hashMap . Contains ( S ) ) { if ( S == 0 ) { return " Yes " ; } return " No " ; } else hashMap . Add ( S ) ; } return " Yes " ; } static void Main ( ) { int S = 3 , D = 6 ; Console . Write ( isDivisibleByDivisor ( S , D ) ) ; } }