Josephus Problem | ( Iterative Solution ) | Iterative solution for Josephus Problem ; Function for finding the winning child . ; For finding out the removed chairs in each iteration ; Driver function to find the winning child
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long int find ( long long int n , long long int k ) { long long int sum = 0 , i ; for ( i = 2 ; i <= n ; i ++ ) sum = ( sum + k ) % i ; return sum + 1 ; } int main ( ) { int n = 14 , k = 2 ; cout << find ( n , k ) ; return 0 ; }