Thursday, July 30, 2015

1038 - Race to 1 Again

#include<bits/stdc++.h>
using namespace std;
vector<int> divisors[100002];
 
void Divisors(int n)
{
    int i,j;
    for(i = 1; i<=n; i++)
        for(j=i; j<=n; j+=i)
            divisors[j].push_back(i);
}
 
int main()
{
    long long T,N,c=1;
    Divisors(100010);
    cin >> T;
    while(T--)
    {
        cin >> N;
        double store[100010];
        long  long l;
        l = divisors[N].size();
        for(long long i=0; i<l; i++)
        {
            if(divisors[N][i] == 1)
                store[divisors[N][i]] = 0;
            else if(divisors[divisors[N][i]].size() == 2)
                store[divisors[N][i]] = 2.000;
            else
            {
                store[divisors[N][i]] = divisors[divisors[N][i]].size();
                for(int j=0; j<divisors[divisors[N][i]].size()-1; j++)
                    store[divisors[N][i]] += store[divisors[divisors[N][i]][j]];
                store[divisors[N][i]] /= divisors[divisors[N][i]].size()-1;
            }
        }
        cout << "Case " << c++ << ": ";
        printf("%.10lf\n",store[divisors[N][l-1]]);
    }
    return 0;
}

No comments:

Post a Comment

Triathlon

Triathlon - CodeChef # include < bits/stdc++.h > using namespace std ; # define fi first # define se second # define mp ...