Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

【map水之】map只存 正式的解,负数通过正数处理得之

Posted by WilliamACM at 2013-03-13 18:42:54 on Problem 1730
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
using namespace std;
#define ll long long
const ll TOP=1ll<<33;
const ll N=1<<17;
map<ll,int> tr;
bool on[N];
void pre()
{
    for(ll i=2;i<N;i++)
    if(!on[i])
    {
        ll k=i*i;
        int cnt=2;
        while(k<TOP&&tr[k]==0)
        {
            if(k<N) on[k]=1;
            tr[k]=cnt++,k*=i;
        }
    }
}
int main()
{
   // freopen("in.txt","r",stdin);
    pre();
    ll n;
    while(scanf("%lld",&n),n)
    {
        bool sp=0;
        if(n<0)
        {
            n=-n;
            sp=1;
        }
        int ans=tr[n];
        if(sp)
        {
            if(ans==0||(ans&1)) printf("%d\n",ans?ans:1);
            else
            {
                int mark=1;
                for(int i=2;i<=ans;i++)
                if(ans%i==0&&((ans/i)&1))
                {
//                    printf("%d %d\n",ans,i);
                    mark=ans/i;
                    break;
                }
                printf("%d\n",mark);
            }
        }else
        printf("%d\n",ans?ans:1);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator