描述:红黑袜子,给出的是红袜子被选到的概率,即为p/q,要计算的是在挑选出一对红袜子之前的红袜子和黑袜子的数目,假设红袜子数为n,黑袜子数为m,那么n(n-1)/(m(m-1))=p/q,求出红袜子数和黑袜子数即可
#include<cstdio>
#include <cmath>
#define LL long long
LL gcd(LL x,LL y)
{
if(x%y==0) return y;
else return gcd(y,x%y);
}
int main()
{
// freopen("in.txt","r",stdin);
LL n,m;
while(scanf("%lld%lld",&n,&m)!=EOF)
{
if(!n&&!m) break;
if(!n)
{
printf("0 2\n");
continue;
}
else if(n==m)
{
printf("2 0\n");
continue;
}
LL p,q,v,x;
x=gcd(m,n);
// printf("x=%lld ",x);
// printf("n=%lld ",n);
n=n/x;
m=m/x;
p=sqrt(2.0*m+0.5);
// if(p%2==1) ++p;
// printf("p=%lld\n",p);
// printf("m=%lld\n",m);
bool flag=0;
for( ; p<=50000 ; ++p)
{
if((p*(p-1))%m!=0) continue;
q=sqrt(p*(p-1)*n/m+0.5);
x=gcd(p*(p-1),q*(q+1));
if(p*(p-1)/x==m&&q*(q+1)/x==n)
{
flag=1;
break;
}
}
if(flag)
{
printf("%lld ",q+1);
printf("%lld\n",p-q-1);
}
else puts("impossible");
//puts("");
}
return 0;
}

10277 - Boastin' Red Socks的更多相关文章

  1. UVA 10277 Boastin' Red Socks

    #include <iostream> #include<cstdio> #include<cstring> using namespace std; unsign ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  4. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. cf581A Vasya the Hipster

    One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red so ...

  6. Vasya the Hipster

    One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red so ...

  7. 使用Red Gate Sql Data Compare 数据库同步工具进行SQL Server的两个数据库的数据比较、同步

    Sql Data Compare 是比较两个数据库的数据是否相同.生成同步sql的工具. 这一款工具由Red Gate公司出品,我们熟悉的.NET Reflector就是这个公司推出的,它的SQLTo ...

  8. 使用Red Gate Sql Compare 数据库同步工具进行SQL Server的两个数据库的结构比较、同步

    将测试版的项目同步(部署)到正式版的时候,两个数据库的结构比较与同步时,如果修改数据库的时候没有记录好修改了那些表,很难将两个数据库进行同步 RedGate Sql Compare使用简介说明: 1. ...

  9. 新年抢红包效果(New Year Red Packet)

    新年抢红包效果(New Year Red Packet) 晓娜的文章(微信公众号:migufe) 2016即将过去,我们将迎来新的一年2017,这里小编提前祝大家新年快乐!万事如意!那我们新年最开心的 ...

随机推荐

  1. sql server drop talbe 自动删除关联的外键 ,权限体系(一)

    if object_id('Proc_DropTableWithFK') is not null begin drop proc dbo.Proc_DropTableWithFK end GO ) a ...

  2. 怎样下载并编译Android4.0内核源代码goldfish(图文)

    关于怎样下载Android4.0源代码,请查看我的博客内还有一篇文章(相同是图文教程): http://blog.csdn.net/flydream0/article/details/7036156 ...

  3. SQL data reader reading data performance test

    /*Author: Jiangong SUN*/ As I've manipulated a lot of data using SQL data reader in recent project. ...

  4. jQuery多文件

    jQuery多文件下载 文件下载是一个Web中非常常用的功能,不过你是做内部管理系统还是做面向公众的互联网公司都会遇到这个问题,对于下载一般有点实际开发经验的都会自己解决,上周弄了一下多文件下载,业务 ...

  5. OCP-1Z0-051-题目解析-第4题

    4. Which two statements are true regarding single row functions? (Choose two.) A. They a ccept only ...

  6. 读书笔记—CLR via C#章节11-13

    前言 这本书这几年零零散散读过两三遍了,作为经典书籍,应该重复读反复读,既然我现在开始写博了,我也准备把以前觉得经典的好书重读细读一遍,并且将笔记整理到博客中,好记性不如烂笔头,同时也在写的过程中也可 ...

  7. sql语句 面试题

    ql语句 面试题   自动编号   学号   姓名 课程编号 课程名称 分数 1        2005001  张三  0001      数学    69 2        2005002  李四 ...

  8. jquery调用wcf案例

    ----------根据其他网友总结 1.在契约接口上添加:[WebInvoke(RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessa ...

  9. WCF、Web API、WCF REST、Web Service 区别

    Web Service It is based on SOAP and return data in XML form. It support only HTTP protocol. It is no ...

  10. Solrcloud,tomcat,外部zookeeper配置