#include <iostream> #include <queue> #include <cstdio> #include <cstring> using namespace std; int n,k; int d[100010]; void bfs() { queue<int> q; memset(d,-1,sizeof(d)); d[0]=0; q.push(0); while(!q.empty()) { int t=q.front(); q.pop(); int a=(t+1)%n; if (d[a]==-1) { d[a]=d[t]+1; q.push(a); } int b=(t+k)%n; if (d[b]==-1) { d[b]=d[t]+1; q.push(b); } } return ; } int main() { scanf("%d%d",&n,&k); bfs(); int res=0; for(int i=1;i<=n;i++) res=max(res,d[i]); printf("%d",res); return 0; }
0.0分
1 人评分
【计算球体积】 (C语言代码)浏览:1101 |
Hello, world! (C语言代码)浏览:714 |
printf基础练习2 (C语言代码)浏览:503 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:600 |
IP判断 (C语言代码)浏览:533 |
震宇大神的杀毒软件 (C语言代码)浏览:1079 |
矩阵的对角线之和 (C语言代码)浏览:1346 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:581 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:607 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:467 |