Timus 1023(Bash Game)

// bash game
#include <stdio.h>
#include <memory>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <time.h>
#include <limits>
using namespace std;
int cal(int a){
 int b, ans;
 ans = inf;
 for(b = 1; b * b <= a; b++){
  if(!(a % b)){
   if(b > 2 && b < ans) ans = b;
   if((a / b) > 2 && (a / b) < ans) ans = (a / b);
  }
 }
 if(ans < inf) return ans - 1;
 else return a - 1;
}
int main(){
#ifndef ONLINE_JUDGE
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
#endif
 init();
 int a;
 while(~scanf("%d", &a)){
  printf("%d\n", cal(a));
 }
 return 0;
}

 

 

posted on 2011-01-17 13:24 tw 阅读(89) 评论(0)  编辑 收藏 引用 所属分类: Timus题解


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿

文章分类

文章档案

搜索

最新评论