首页 > 其他 > 详细

URAL 2070 Interesting Numbers(数学)

时间:2016-08-22 21:49:18      阅读:263      评论:0      收藏:0      [点我收藏+]

题目地址:http://acm.timus.ru/problem.aspx?space=1&num=2070

思路:质数一定满足题意(满足条件一,因子数为2为质数)。所以只需求出l到r中的合数且因子数为质数的数的个数。该数质因子只能为1(若大于一,则因子数为合数),所以枚举每个质数,若该质数的指数+1(因子数)为质数,则ans--。

#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxx=1e6;
LL l,r;
int v[maxx];
vector<int> prime;
void prepare()
{
    for(int i=2; i<maxx; i++)
    {
        if(!v[i])
        {
            prime.push_back(i);
            for(int j=2*i; j<maxx; j+=i) v[j]=1;
        }
    }
}
LL solve()
{
    LL ans=r-l+1;
    for(int i=0; i<prime.size(); i++)
    {
        LL now=1,tot=0;
        while(now<l) now*=prime[i],tot++;
        while(now<=r)
        {
            if(tot>1&&!v[tot+1])ans--;
            now*=prime[i],tot++;
        }
    }
    cout<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(0);
    prepare();
    cin>>l>>r;
    solve();
    return 0;
}


URAL 2070 Interesting Numbers(数学)

原文:http://blog.csdn.net/wang2147483647/article/details/52279872

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!