Registrations for the November 2021 System Design Cohort are now open Enroll Today

ANARC08H Solution



#include <stdio.h>
 
int jo(int n, int k) {
	int ans = 0, i;
	for(i = 2; i <= n; i++) ans = (ans + k) % i;
	return ans+1;
}
 
int main() {
	int n , k;
	scanf("%d%d" , &n , &k);
	while ( n != 0 && k != 0 ) {
		printf("%d %d %d\n", n , k , jo(n, k));
		scanf("%d%d" , &n , &k);
	}
	return 0;
}

470+ Competitive Programming Solutions

If you like what you read subscribe to my newsletter.

I write essays on various engineering topics and share it through my weekly newsletter 👇