• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codechef November Challenge 2013 Yet Another Cute Girl

Yet Another Cute Girl

Problem code: PRETNUM

  • Submit
  • My Submissions
  • All Submissions
 

Read problems statements in Mandarin Chinese and Russian.

Chef doesn't love math anymore. He loves Sasha. Sashen'ka is cute.

Chef goes on a date with her. Flowers are boring, while numbers are not. He knows that most of all this girl loves numbers, that's why he is going to bring ribbon with numbers L, L+1, L+2, ..., R written on it.

Sasha thinks that numbers with prime number of divisors are special. That's why she is going to kiss boy for each such number he will bring.

Now Chef wonder how many times he will be kissed by Sashen'ka ?

 

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains two number L, R.

 

Output

For each test case, output a single line containing answer for corresponding test case.

 

Constraints

  • 1 ≤ T ≤ 5
  • 1 ≤ L ≤ R ≤ 1012
  • 0 ≤ R-L ≤ 106

 

Example

Input:
1
1 10

Output:
6

 

Explanation

Example case 1. Numbers 2,3,4,5,7,9 are special.

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cstdlib>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define maxn 1000011
14 #define ll long long
15 #define mod 1000000007
16 #define INF 0x7fffffff
17 #define eps 1e-8
18 ll n, m;
19 int pri[maxn];
20 int prv[maxn];
21 int pv[maxn];
22 int main(){ 
23     int t, k = 1,x=0; 
24     prv[1] = 1; prv[0] = 1; pri[0] = 2;
25     for (int i = 2; i <= 1000000; i++)
26     if (!prv[i])
27     for (ll j = (ll) i*i; j <= 1000000; j += i)
28     if (!prv[j])prv[j] = 1;
29     for (int i = 3; i <= 1000000; i+=2)
30     if (!prv[i])pri[k++] = i;
31     scanf("%d", &t);
32     while (t--){
33         ll ans1 = 0, ans2 = 0, t1 = 0, t2 = 0, ans = 0;
34         scanf("%lld%lld", &n, &m);
35         for (int i = 0; i < k; i++){
36             ll s = pri[i]; t1 = 0; t2 = 0;
37             for (int j = 0;; j++){
38                 s *= pri[i];
39                 if (!prv[j+3]&&s<n)t1++;
40                 if (!prv[j+3]&&s<=m)t2++;
41                 if (s>=m)break;
42             }
43             ans1 += t1;ans2 += t2;
44         }
45         memset(pv, 0, sizeof pv);
46         if (n == 1)n++;
47         for (int i = 0; i < k; i++){
48             ll j = n / pri[i] * pri[i];
49             if (j < (ll)pri[i] * pri[i])j = (ll)pri[i] * pri[i];
50             for (; j <= m; j += pri[i])
51             if (j >= n&&(!pv[j - n] || j <= 1000000 && prv[j]))pv[j - n] = 1;
52         }
53         for (int i = 0; i <= m - n; i++)if (!pv[i])ans++;
54         ans += ans2 - ans1;
55         printf("%lld\n", ans);
56     }
57     return 0;
58 }
View Code
posted @ 2013-11-06 00:10  HaibaraAi  阅读(194)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3