题目描述的意思就不说了,自己考虑的时候就是在所有的排列中,碰到大于前面最大的出现数字的时候就乘以一个二分之一,然后求和。

打表后就会发现,答案分子为1*3*5*……*(2*n-1);分母为2*4*6*……*(2*n),这样就很简单了。

直接保存每一个因子出现的次数,然后。。。就可以了。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#define M 1000000
#define maxn 1011
using namespace std; struct node{
int top,s[];
void init()
{
for (int i=; i<=top; i++) s[i]=;
top=,s[]=;
}
void mul(int x)
{
for (int i=; i<=top; i++) s[i]*=x;
for (int i=; i<top; i++)
if (s[i]>=M) s[i+]+=s[i]/M,s[i]%=M;
while (s[top]>=M) s[top+]=s[top]/M,s[top]%=M,top++;
}
void output()
{
printf("%d",s[top]);
for (int i=top-; i>=; i--) printf("%06d",s[i]);
}
}ans1,ans2; int a[maxn],pri[maxn],Pnum=;
bool b[maxn]; void getprim()
{
for (int i=; i<maxn; i++)
{
if (b[i]) continue;
pri[++Pnum]=i;
for (int j=i+i; j<maxn; j+=i) b[j]=true;
}
} void add(int x,int v)
{
for (int i=; pri[i]<=x; i++)
{
while (x%pri[i]==) x/=pri[i],a[i]+=v;
}
} int main()
{
int T,n;
getprim();
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
memset(a,,sizeof a);
for (int i=; i<=*n; i+=) add(i,);
for (int i=; i<=*n; i+=) add(i,-);
ans1.init(),ans2.init();
for (int i=; i<=Pnum; i++)
{
while (a[i]>) ans1.mul(pri[i]),a[i]--;
while (a[i]<) ans2.mul(pri[i]),a[i]++;
}
ans1.output();
printf("/");
ans2.output();
printf("\n");
}
return ;
}

HDU4043_FXTZ II的更多相关文章

  1. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  2. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

  3. 函数式Android编程(II):Kotlin语言的集合操作

    原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...

  4. 统计分析中Type I Error与Type II Error的区别

    统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...

  5. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  6. [LeetCode] Guess Number Higher or Lower II 猜数字大小之二

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  7. [LeetCode] Number of Islands II 岛屿的数量之二

    A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...

  8. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  9. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

随机推荐

  1. pwd命令的实现

    pwd 命令描述 Linux中用 pwd 命令来查看"当前工作目录"的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd ...

  2. 20155310第一周JAVA实验报告

    20155310第一周JAVA实验报告 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实验要求 使用JDK和IDE编译.运行简单 ...

  3. Object重写equals()、hashcode()方法的原因

    一.问题 在我们新建java对象的时候,如果后期用到对象比较,就必须重写equals(0.hashcode()方法 为什么必须重写这两个方法? 只是比较相等的话,重写equals()方法不就可以吗?为 ...

  4. Windows下安装RaibbitMQ

    1.软件准备 1.1 erlang语言包 到http://www.erlang.org/download.html下载,并且运行! 安装目录C:\Program Files (x86)\erl5.10 ...

  5. 【CF833D】Red-Black Cobweb

    [CF833D]Red-Black Cobweb 题面 洛谷 题解 看到这种统计路径的题目当然是淀粉质啦. 考虑转化一下信息设一条路径上有红点\(a\)个,黑点\(b\)个 则\(2min(a,b)\ ...

  6. Eclipse 使用过程中的问题及解决方法

    1.Eclipse中java文件和jsp字体大小设置 1.更改所有文件的字体显示大小过程: Window->preferences->General->Appearance-> ...

  7. Spark 序列化问题

    在Spark应用开发中,很容易出现如下报错: org.apache.spark.SparkException: Task not serializable at org.apache.spark.ut ...

  8. AWS探索及创建一个aws EC2实例

    一.AWS登陆 1.百度搜索aws,或者浏览器输入:http://aws.amazon.com 2.输入账户及密码登陆(注册流程按照提示走即可) 二.创建EC2实例(相当于阿里云的ecs) 1.找到E ...

  9. animation和transition

    相同点 指定要侦听更改的CSS属性. 设置计时(缓和)功能以改变从一个属性值到另一个属性值的速率 指定持续时间以控制动画或转换所需的时间 以编程方式收听您可以随意执行的动画和特定于转换的事件 可视化C ...

  10. hdfs遍历文件方法

    import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org. ...