UVa10375

题目描述很简单,就是求两个组合数的商.可是数字范围很大,肯定不能直接计算.

因此要用到唯一分解定理,即将结果全部表示为素因子的幂的形式.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<climits>
#include<cctype>
#include<queue>
#include<set>
#include<cmath>using namespace std;typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=1e4+5;
bool check[MAXN];
int prime[MAXN];
int cnt[MAXN];
int tot;
int p,q,r,s;void creat_prime()
{tot=0;for(int i=2;i<MAXN;i++){if(!check[i]) prime[tot++]=i;for(int j=0;j<tot && prime[j]*i<MAXN ;j++){check[prime[j]*i]=true;if(i%prime[j]==0) break;}}
}void add(int l,int r,int d)
{for(int i=l;i<=r;i++){int t=i;for(int j=0;j<tot;j++){while(t%prime[j]==0){cnt[j]+=d;t/=prime[j];}if(t==1) break;}}
}int main()
{creat_prime();while(~scanf("%d%d%d%d",&p,&q,&r,&s)){memset(cnt,0,sizeof(cnt));add(1,r-s,1);add(q+1,p,1);add(1,p-q,-1);add(s+1,r,-1);double ans=1.0;for(int i=0;i<tot;i++){ans*=pow(prime[i],cnt[i]);}printf("%.5f\n",ans);}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/383955.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

I/O复用的 select poll和epoll的简单实现

http://www.cnblogs.com/wj9012/p/3876734.html 一个tcp的客户端服务器程序 服务器端不变&#xff0c;客户端通过I/O复用轮询键盘输入与socket输入&#xff08;接收客户端的信息&#xff09; 服务器端&#xff1a; 1 /*服务器:2 1.客户端关闭后&#xff0c;服务器再向客户端发送…

netstat 相关命令解析

1.列出所有的端口 netstat -a 列出TCP协议的端口 netstat -at UDP协议的端口 netstat -au 2.列出处于监听状态的socket netstat -l 列出监听的TCP端口 netstat -lt 列出监听的UDP端口 netstat -lu 列出监听的UNIX端口 netstat -lx 3.列出协议的统计信息 nestat …

UVa10791

我们可以先用唯一分解定理将这个数字分解成素因子幂的乘积&#xff0c;为了得到最小的和&#xff0c;我们可以发现&#xff1a;每个 素因子的幂单独分开的和是最小的。 先说明每个素因子都是以出现的最大的次数出现。因为最小公倍数一定&#xff0c;因此至少有一个数字的这个素…

TCP相关代码

TCP 基础代码 //tcp_server.c #include<stdio.h> #include<error.h> #include<sys/types.h> #include<string.h> #include<unistd.h> #include<sys/socket.h> #include<netinet/in.h> #include <arpa/inet.h> #include<st…

UVa1635

我们很容易发现最后每一项的系数就是二项式展开&#xff0c;余数和m没有关系就意味着可以被m整除&#xff0c;因此我们就需要求出每一个二项式的系数。但是数据实在太大我们根据唯一分解定理将m和系数都进行分解&#xff0c;然后比较因子的幂。 二项式的计算我们可以根据杨辉三…

几种并发服务器模型的实现:多线程,多进程,select,poll,epoll

http://www.cnblogs.com/wj9012/p/3879605.html 客户端使用select模型&#xff1a; 1 #include <stdio.h>2 #include <stdlib.h>3 #include <string.h>4 #include <errno.h>5 #include <sys/types.h>6 #include <sys/socket.h>7 #include …

哈希表1

1. 初始化 void HashInit(HashTable* ht, HashFunc func) {if(ht NULL || func NULL){return;}ht -> size 0;ht -> func func;int i 0;for(; i < HashMaxSize; i){ht -> data[i].state Empty;} } 2. 哈希表的销毁 void HashDestroy(HashTable* ht) {if(ht…

UVa10820

实质上就是求欧拉函数值 书上有个板子挺好&#xff0c;也不难理解。 #include<cstdio> #include<cstring> #include<algorithm> #include<climits> #include<cctype> #include<queue> #include<set>using namespace std;typedef l…

linux socket 编程(C语言)

https://www.cnblogs.com/x_wukong/p/4541010.html 最近看了一些网络编程的书籍&#xff0c;一直以来总感觉网络编程神秘莫测&#xff0c;其实网络编程入门还是很容易学的&#xff0c;下面这些代码是我在linux下编写的&#xff0c;已经运行过了&#xff0c;编译之后就可以运行了…

哈希表2

哈希表的初始化 void HashInit(HashTable* ht, HashFunc func) {if(ht NULL){return;}ht -> size 0;ht -> func func;size_t i 0;for(; i < MaxSize; i){ht -> data[i] NULL;} } 哈希表的结点创建 HashElem* CreateHashElemNode(KeyType key, ValueType va…

位图

相关数据结构 typedef uint64_t BitmapType;#define BITMAPMAXSIZE 1000 //位图所能容纳的位数typedef struct Bitmap {uint64_t* data;uint64_t capacity; }Bitmap; 初始化 void BitmapInit(Bitmap* bm, uint64_t capacity) {if(bm NULL){return;}//当capacity 100, 2个元…

C++中的inline用法

https://www.cnblogs.com/fnlingnzb-learner/p/6423917.html 1. 引入inline关键字的原因 在c/c中&#xff0c;为了解决一些频繁调用的小函数大量消耗栈空间&#xff08;栈内存&#xff09;的问题&#xff0c;特别的引入了inline修饰符&#xff0c;表示为内联函数。 栈空间就是指…

UVa1262

算是一个模拟吧 #include<cstdio> #include<cstring> #include<algorithm> #include<climits> #include<cctype> #include<queue> #include<set> #include<vector>using namespace std;typedef long long ll; const int INF…

一个Linux下C线程池的实现

http://blog.csdn.net/zouxinfox/article/details/3560891 什么时候需要创建线程池呢&#xff1f;简单的说&#xff0c;如果一个应用需要频繁的创建和销毁线程&#xff0c;而任务执行的时间又非常短&#xff0c;这样线程创建和销毁的带来的开销就不容忽视&#xff0c;这时也是线…

Gym100917 A - Abstract Picture

模拟赛的时候看这道题没有什么头绪&#xff0c;当时有点晕&#xff0c;感冒还没有好&#xff0c;回来以后瞟了一眼题解就明白了&#xff0c;自己实现了一下&#xff0c;也没有很复杂。大概的思路就像拓扑排序一样&#xff0c;需要理解因为涂的是有顺序的&#xff0c;所以我们总…

linux进程通信---几个发送信号的函数(kill,raise,alarm,pause)

http://blog.csdn.net/zzyoucan/article/details/9235685 信号&#xff1a;信号是unix中最古老的进程通信的一种方式&#xff0c;他是软件层次上对中断机制的模拟&#xff0c;是一种异步通信方式&#xff0c;信号可以实现用户空间进程和内核空间进程的交互&#xff0c;内核进程…

数据库以及表的基本操作

一.数据库的操作 create database[if not exists]数据库名; 创建一个名字为company2的使用utf8忽略大小写的数据库 create database company charsetutf8 collate utf8_general_ci; 创建一个数据库区分大小写 create database company1 charsetutf8 collate utf8_general_bin;…

linux 网络编程:使用两线程实现socket同时收发数据

http://blog.csdn.net/li_wen01/article/details/52665505 工作中最近有使用到socket 向客户端同时发送和接收数据&#xff0c;因为是嵌入式linux设备&#xff0c;且要求只能同时一个客户端连接该端口。考虑到节省系统资源&#xff0c;只创建了两个线程分别实现服务端的收发数据…

CF Gym102059 H. Fractions

题目要求找到给定区间的化简后分子分母的和小于1000的数字的个数 我的想法是先找到所有的满足要求的最简分数(总数不超过1e6,而且远小于),然后对询问查找每个最简分数出现的次数. #include<cstdio> #include<cstring> #include<algorithm> #include<cli…

C语言calloc()函数:分配内存空间并初始化

http://c.biancheng.net/cpp/html/134.html 头文件&#xff1a;#include <stdlib.h> calloc() 函数用来动态地分配内存空间并初始化为 0&#xff0c;其原型为&#xff1a; void* calloc (size_t num, size_t size); calloc() 在内存中动态地分配 num 个长度为 siz…