题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126

 /*
找规律,智商不够,看了题解
详细解释:http://blog.csdn.net/ahfywff/article/details/7432524
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f; int GCD(int a, int b)
{
return b ? GCD (b, a % b) : a;
} int main(void) //SGU 126 Boxes
{
//freopen ("C.in", "r", stdin); int n, m; while (~scanf ("%d%d", &n, &m))
{
int ans;
if (n == || m == )
{
ans = ;
}
else
{
if (n < m) swap (n, m);
int k = GCD (n, m);
int x = n / k; int y = m / k;
if ((x+y) & )
{
ans = -;
}
else
{
int tmp = x + y;
ans = ;
while (tmp > )
{
if (tmp % == )
{
tmp /= ;
ans++;
}
else
{
ans = -; break;
}
}
}
} printf ("%d\n", ans);
} return ;
}

找规律 SGU 126 Boxes的更多相关文章

  1. sgu 126 Boxes

    题意:较大的容量减较小的容量,较小的容量翻倍.问操作几回其中一个空. 开始用set判重,重复就不可行.不过状态最多有2e18种.不仅爆内存,还超时.然后找规律.发现只有比例为1:1,1:3,1:7,3 ...

  2. SGU 126 Boxes(模拟题|二进制)

    Translate:Sgu/126 126. 盒子 time limit per test: 0.5 sec. memory limit per test: 4096 KB 有两个盒子. 第一个盒子里 ...

  3. SGU 126. Boxes --- 模拟

    <传送门> 126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two b ...

  4. 找规律 SGU 107 987654321 problem

    题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=107 /* 题意:n位数的平方的后面几位为987654321的个数 尼玛,我看描述这 ...

  5. SGU 107 987654321 problem【找规律】

    题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=107 题意: 平方后几位为987654321的n位数有多少个 分析: 虽然说是水题 ...

  6. SGU 169 Numbers (找规律)

    题意:中文题,直接忽略... 析:先说说我的思路,我一看这个题第一感觉就是要找规律,要是挨着算,猴年马月都跑不完,更何况时间限制是0.25s,怎么找规律呢,我算了一下前10位,分别是8,1,1,3,1 ...

  7. 找规律 ZOJ3498 Javabeans

    Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...

  8. ZOJ 3498 Javabeans(找规律)

    Javabeans Time Limit: 2 Seconds      Memory Limit: 65536 KB Javabeans are delicious. Javaman likes t ...

  9. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

随机推荐

  1. Model backing a DB Context has changed; Consider Code First Migrations

    Model增加一个字段,数据库对应的也手动添加了字段但是运行时报错 The model backing the 'TopLogDbContext' context has changed since ...

  2. reverse array java

    /* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import ...

  3. Pascal’s Triangle

    vector<vector<int>> generate(int num) { vector<vector<int>> result; vector&l ...

  4. HDU2191多重背包例题

    悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %I64d ...

  5. 如何下载google play免费应用的apk文件

    到这里: http://apps.evozi.com/apk-downloader/ 一看便知.

  6. 【SpringMVC】SpringMVC系列3之@PathVariable映射URL占位符参数

    3.@PathVariable映射URL占位符参数 3.1.概述 带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义. ...

  7. MyBatis3: There is no getter for property named 'code' in 'class java.lang.String'

    mybatis3  : mysql文如下,传入参数为string类型时‘preCode’,运行报错为:There is no getter for property named 'preCode' i ...

  8. windows电脑变成wifi热点命令

    netsh wlan set hostednetwork mode=allow ssid=WIFI_NAME key="abcdefgh" netsh wlan start hos ...

  9. CodeForces - 405A

    Gravity Flip Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit ...

  10. plsql查询数据显示为乱码解决方法

    使用plsql查询数据显示为乱码: 查看数据库编码: 通过网上搜索,发现需要设置环境变量,添加以下环境变量: LANG=zh_CN.GBK NLS_LANG="SIMPLIFIED CHIN ...