SPOJ–TIGA J - Nuts Frenzy

Ivan, Filbert, and Tracy really like nuts. They can eat nuts without stopping all day long if they want to. Today they decided to buy some nuts so each one of them get exactly K nuts (1<=K<=1,000,000,000) and they want to eat it all. To make it interesting, they are only allowed to eat a certain number of nuts every second.

  • Ivan can eat at max I nuts per second. (1<=I<=1,000,000)
  • Filbert can eat at max K/F nuts per second. (1<=F<=100)
  • Tracy can eat at max the sum of all the factors of K excluding 1 and K nuts per second.

They are not allowed to eat only a fraction of a nut every second, and they must eat a minimum of 1 nut every second regardless of the previous rule. They can stop eating after they run out of nuts. Your task is to determine the time needed (in seconds) for each of them to finish their nuts!

Input

The first line of input is T, the number of test case. (T<20)
The next T lines each consists of three numbers K, I, and F separated by a space.

Output

For each test case, output the minimum time needed for Ivan, Filbert, and Tracy to finish their nuts.

Example
Input:

3
10 2 5
100 10 4
121 100 1

Output:

5 5 2
10 4 1
2 1 11

———————————————————————感想———————————————————————————————————

这次比赛爆炸,估计无缘省赛,想想还是有点郁闷的……毕竟第一天最后发挥了一把感觉还不错,然后就被第二天的题目狠狠打了脸,而且是一道连整天划水的人都做得出来的题目……果然还是需要多多的练习啊。

这道题目其他两个不难,比较烦的就是求一个10^9的数字的所有因数,一看起来就感觉很难,脑子里的思维全部跑到了类似于分解质因数啊,关于10^9的因数计算之类的,完全没有注意到因数必然有一个大一个小,小的和大的一一对应,且两者最相近的时候是根号K,也就是10^5到10^4左右,完完全全是可以直接暴力的……

然后还有一个被卡住的trick是虽然这个k没有超过int的范围,但是其因数和是可以爆int的,如果不注意的话很可能被卡一下。

哎……很不爽啊……

————————————————————————————————————————————————————————————

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<climits>
#include<map>
#include<stack>
#include<cmath>
#define file_in freopen("in.txt","r",stdin)
#define MAX 200000
#define maxn 5005
using namespace std;
#define LL int
#define FF(x,y) for(int i=x;i<y;i++)
int stall[MAX];
bool av[MAX];
int dis[MAX];
int main()
{
    int t;
    scanf("%d", &t);
    for (int i = 0; i<t; i++)
    {
        LL k, ii, f;
        LL ti, tf, tk = 0;
        scanf("%d %d %d", &k, &ii, &f);
        LL ff = k / f;
        if (ff == 0)ff = 1;
        long long sum = 0;
        for (int i = 2; i<=int(sqrt(double(k))); i++)
        {
            if (k%i == 0)
            {
                sum += i;
                if (k / i > i)sum += k / i;
            }
        }
        if (k%ii)ti = k / ii + 1;
        else ti = k / ii;
        if (k%ff)tf = k / ff + 1;
        else tf = k / ff;
        if (!tk)
        {
            if (sum == 0)
                tk = k;
            else
            {
                if (k%sum)tk = k / sum + 1;
                else tk = k / sum;
            }
        }
        printf("%d %d %d\n", ti, tf, tk);
    }
}

posted @ 2017-02-27 14:02  duskcloudxu  阅读(151)  评论(0编辑  收藏  举报