URAL 2070 Interesting Numbers(数学)

题目地址: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;
}

时间: 2024-12-28 19:46:21

URAL 2070 Interesting Numbers(数学)的相关文章

【线性筛】【筛法求素数】【约数个数定理】URAL - 2070 - Interesting Numbers

素数必然符合题意. 对于合数,如若它是某个素数x的k次方(k为某个素数y减去1),一定不符合题意.只需找出这些数. 由约数个数定理,其他合数一定符合题意. 就从小到大枚举素数,然后把它的素数-1次方都排除即可. #include<cstdio> #include<cmath> using namespace std; #define MAXP 1000100 #define EPS 0.00000001 typedef long long ll; ll L,R; bool isNo

URAL 2070 Interesting Numbers (找规律)

题意:在[L, R]之间求:x是个素数,因子个数是素数,同时满足两个条件,或者同时不满足两个条件的数的个数. 析:很明显所有的素数,因数都是2,是素数,所以我们只要算不是素数但因子是素数的数目就好,然后用总数减掉就好.打个表,找找规律,你会发现, 这些数除外的数都是素数的素数次方,然后就简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include &

Timus 2070 Interesting Numbers

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2070 题目描述: 题目大意是给定范围[L, R],求该范围中interesting数的个数. interesting数的定义为: 1.素数 2.不为素数且其正因子的个数不为素数个(如:6: 1,2,3,6) 计算正因子的个数一般使用的是分解质因数了,若 n = p1^a1 * p2^a2 * ... pm^am 那么正因子的个数为 k = (a1+1) * (a2+1) * ... * (am

算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)

目录 1 问题描述 2 解决方案   1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its digits consists of only 0, 1, 2 and 3, and all these digits occurred at least once. 2. Inside this number, all 0s occur before any 1s, and all 2s occur

POJ 3252 Round Numbers 数学题解

Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets

递推DP URAL 1586 Threeprime Numbers

题目传送门 1 /* 2 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 3 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 4 所以,dp[i][j][k] 表示i位数字,最高位数字j,第二高位数字k 5 状态转移方程:dp[i][j][k] += dp[i-1][k][l] 6 注意:最高位从1开始枚举:) 7 详细解释:http://blog.csdn.net/zhangyanxing666/article/detai

Codeforces 747F Igor and Interesting Numbers dp

Igor and Interesting Numbers 枚举每一位, 用dp去算方案数. #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair&

URAL 2031. Overturned Numbers (枚举)

2031. Overturned Numbers Time limit: 1.0 second Memory limit: 64 MB Little Pierre was surfing the Internet and came across an interesting puzzle: What is the number under the car? It took some time before Pierre solved the puzzle, but eventually he u

URAL 2003. Simple Magic(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2003 2003. Simple Magic Time limit: 1.0 second Memory limit: 64 MB Do you think that magic is simple? That some hand-waving and muttering incomprehensible blubber is enough to conjure wonderful garden