10277 - Boastin' Red Socks
描述:红黑袜子,给出的是红袜子被选到的概率,即为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的更多相关文章
- UVA 10277 Boastin' Red Socks
		#include <iostream> #include<cstdio> #include<cstring> using namespace std; unsign ... 
- UVA题目分类
		题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ... 
- HOJ题目分类
		各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ... 
- 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 ... 
- 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 ... 
- 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 ... 
- 使用Red Gate Sql Data Compare 数据库同步工具进行SQL Server的两个数据库的数据比较、同步
		Sql Data Compare 是比较两个数据库的数据是否相同.生成同步sql的工具. 这一款工具由Red Gate公司出品,我们熟悉的.NET Reflector就是这个公司推出的,它的SQLTo ... 
- 使用Red Gate Sql Compare 数据库同步工具进行SQL Server的两个数据库的结构比较、同步
		将测试版的项目同步(部署)到正式版的时候,两个数据库的结构比较与同步时,如果修改数据库的时候没有记录好修改了那些表,很难将两个数据库进行同步 RedGate Sql Compare使用简介说明: 1. ... 
- 新年抢红包效果(New Year Red Packet)
		新年抢红包效果(New Year Red Packet) 晓娜的文章(微信公众号:migufe) 2016即将过去,我们将迎来新的一年2017,这里小编提前祝大家新年快乐!万事如意!那我们新年最开心的 ... 
随机推荐
- C_数据结构
			线性结构 线性结构的特点是:在数据元素的飞空有限集中,(1)存在唯一的一个被称作“第一个”的数据元素:(2) 存在唯一一个被称做“最后一个”的数据元素:(3)除第一个外,集合中的每一个元素都只有一个前 ... 
- MyReport报表引擎2.7.6.7新功能
			新增二维码控件PDF417 设计器新增数据选项卡,可以拖放字段进行绑定 相关链接 MyReport演示.产品站点 相关文章 MyReport专栏 
- 让你的Windows不断重启的C语言代码
			原文:让你的Windows不断重启的C语言代码 没有写Linux的原因是因为搞不定Linux下的权限问题,而Windows下基本上使用电脑的用户都是管理员,所以钻个空了,不多说下面是代码#includ ... 
- 谈论quick-cocos2d-x和cocos2d-x lua了解差异
			之前说,我把这个两个词区别.经过太长时间.当然,反击的麻烦.quick-cocos2d-x它提到quick,cocos2d-x lua姑且称为本地lua对. 我认为,首先与这两个小的朋友接触会跟着或多 ... 
- Linux下给mysql创建用户分配权限
			1.新建用户 //登录MYSQL @>mysql -u root -p @>密码 //创建用户 mysql> insert into mysql.user(Host,User,Pas ... 
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
			题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ... 
- 调试javascript
			Chrome 控制台 如何调试javascript 上面的文章已经大致介绍了一下console对象具体有哪些方面以及基本的应用,下面简单介绍一下如何利用好chrome控制台这个神器好好调试javasc ... 
- oledb快速导入Excel案例
			DataTable dtImportExcel = null; string pathFile = Server.MapPath("~/ErrorCatory.xlsx"); // ... 
- sql简单实用的统计汇总案例参考
			USE [PM]GO/****** 对象: StoredProcedure [dbo].[LfangSatstics] 脚本日期: 08/24/2013 10:57:48 ******/SET ... 
- mysql删除和修改数据报错1175
			当用MySQL Workbench进行数据库的批量更新时,执行一个语句会碰到以下错误提示: Error Code: 1175 You are using safe...without a WHERE ... 
