//问一个区间[a,b]与n互素的数的个数

//利用容斥原理可知

//在[a,b] 区间内对n的素数因子

//ans = 被一个数整除的数的个数 - 被两个数的最小公倍数整除的数的个数 + 被三个数的。。。

#include<cstdio>

#include<cstring>

#include<iostream>

using namespace std ;

const int maxn = 100010 ;

typedef __int64 ll ;

ll p[maxn] ;int len ;

void get_prime(ll n)

{

    len = 0 ;

    for(ll i = 2;i*i <= n;i++)

    {

        if(n%i == 0)p[++len] = i ;

        while(n%i == 0)n/=i ;

    }

    if(n>1)p[++len] = n;

}

ll dfs(int pos , ll n)

{

    ll ans = 0 ;

    for(int i = pos ;i <= len ;i++)

        ans += n/p[i] - dfs(i+1 , n/p[i]) ;

    return ans ;

}

int main()

{

    ll a , b ,n ;

    int T ;

    int cas =  0 ;

    scanf("%d" ,&T) ;

    while(T--)

    {

        scanf("%I64d%I64d%I64d" , &a , &b , &n);

        get_prime(n) ;

        ll ans = (b - dfs(1 , b)) - (a  - 1 - dfs(1 , a-1)) ;

        printf("Case #%d: " ,++cas) ;

        printf("%I64d\n" , ans) ;

    }

    return  0 ;

}

hdu4135Co-prime 容斥原理水题的更多相关文章

  1. UESTC--1272--Final Pan's prime numbers(水题)

    Final Pan's prime numbers Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & % ...

  2. Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题

    C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...

  3. UVa 1644 Prime Gap (水题,暴力)

    题意:给定一个数 n,求它后一个素数和前一个素数差. 析:先打表,再二分查找. 代码如下: #pragma comment(linker, "/STACK:1024000000,102400 ...

  4. POJ2485Highways(prime 水题)

    Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26516   Accepted: 12136 Descri ...

  5. 【UVA - 1644 / POJ - 3518】Prime Gap(水题)

    Prime Gap 这里直接写中文了 Descriptions: 对于一个数n,若n为素数则输出0,否则找到距离n最小的两个素数,一个大于n,一个小于n,输出他们的差(正数) Input 多组输入 每 ...

  6. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  7. 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)

    算法训练 Torry的困惑(基本型) 时间限制:1.0s   内存限制:512.0MB      问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...

  8. HDU 4813 Hard Code 水题

    Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  9. LOJ #6303. 水题 (约数 质因数)

    #6303. 水题 内存限制 10 MiB 时间限制:1000 ms 标准输入输出 题目描述 给定正整数 n,kn, kn,k,已知非负整数 xxx 满足 n!modkx=0,求 xmaxx_{max ...

随机推荐

  1. python使用post登陆电子科大信息门户并保存登陆后页面

    python使用post登陆电子科大信息门户并保存登陆后页面 作者:vpoet mail:vpoet_sir@163.com #coding=utf-8 import HTMLParser impor ...

  2. UVA10487(二分)

    Given is a set of integers and then a sequence of queries. A query gives you a number and asks to fin ...

  3. Ffmpeg和SDL如何同步音频

    ong> 同步音頻 现在我们已经有了一个比较像样的播放器.所以让我们看一下还有哪些零碎的东西没处理.上次,我们掩饰了一点同步问题,也就是同步音频到视频而不是其它的同步方式.我们将采用和视频一样的 ...

  4. Flashback Version/Transaction Query

    1.应用Flashback Version Query查询记修改版本 SQL> select dbms_flashback.get_system_change_number from dual; ...

  5. mysql密码忘记如何处理

    1,修改/etc/my.cnf添加添加skip-grant参数,重启mysql. 2,登录mysql  mysql -uroot 3, 更新user中root的密码  use mysql;   upd ...

  6. 线程:Java主线程等待子线程结束

    使用Thread.join()方法: public class App { public static void main(String[] args) { testMain(); } public ...

  7. Entity Framework with MySQL

    Get Entity Framework: http://msdn.microsoft.com/en-us/data/ee712906 Entity Framework 6 Tools for Vis ...

  8. 如何在美国公司写project plan 邮件--以hadoop安装和Mahout数据分析为例子

    Hi, XXX (boss name) Project Title:  Hadoop installation and Data analysis based on Mahout Deliverabl ...

  9. 终极解法According to TLD or attribute directive in tag file, attribute select does not accept any expressions

    3天硬是是把这个问题解决了 有时候突然上个厕所灵感就来了 第一次向用JSTL解析xml 然后我想遍历整个xml文档打印出来 居然不让我输入变量 那让我怎么办啊 在网上各种找答案 说什么<%@ t ...

  10. 计算两个集合的交集数字(java)

    循环判断2个数组 将相同的公共元素复制到新数组中即可 import java.util.Arrays; public class count_same_number { public static i ...