题目链接 Fox Dividing Cheese

思路:求出两个数a和b的最大公约数g,然后求出a/g,b/g,分别记为c和d。

   然后考虑c和d,若c或d中存在不为2,3,5的质因子,则直接输出-1(根据题目要求)

计算出c = (2 ^ a2) * (3 ^ a3) * (5 ^ a5)      d = (2 ^ b2) * (3 ^ b3) * (5 ^ b5)

   那么答案就是a2 + a3 + a5 + b2 + b3 + b5

#include <bits/stdc++.h>

using namespace std;

int a, b;
int n, m, x;
int a2, a3, a5, b2, b3, b5; int gcd(int a, int b){
return b == ? a : gcd(b, a % b);
} int main(){ scanf("%d%d", &n, &m);
if (n == m){puts(""); return ;}
x = gcd(n, m); a = n / x, b = m / x;
while (a % == ) { a /= , ++a2;}
while (a % == ) { a /= , ++a3;}
while (a % == ) { a /= , ++a5;} while (b % == ) { b /= , ++b2;}
while (b % == ) { b /= , ++b3;}
while (b % == ) { b /= , ++b5;} if (a > || b > ){
puts("-1");
return ;
} printf("%d\n", a2 + a3 + a5 + b2 + b3 + b5);
return ; }

Codeforces 371B Fox Dividing Cheese(简单数论)的更多相关文章

  1. codeforces 371B - Fox Dividing Cheese

    #include<stdio.h> int count; int gcd(int a,int b) { if(b==0) return a;     return gcd(b,a%b); ...

  2. CF 371B Fox Dividing Cheese[数论]

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces 371BB. Fox Dividing Cheese

    Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, corre ...

  4. Codeforces Round #218 (Div. 2) B. Fox Dividing Cheese

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. cf B. Fox Dividing Cheese

    http://codeforces.com/contest/371/problem/B #include <cstdio> #include <iostream> #inclu ...

  6. Codeforces - 773A - Success Rate - 二分 - 简单数论

    https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...

  7. Codeforces - 346A - Alice and Bob - 简单数论

    http://codeforces.com/problemset/problem/346/A 观察了一下,猜测和他们的最大公因数有关,除以最大公因数前后结果是不会变的. 那么怎么证明一定是有n轮呢?我 ...

  8. (step7.2.1)hdu 1395(2^x mod n = 1——简单数论)

    题目大意:输入一个整数n,输出使2^x mod n = 1成立的最小值K 解题思路:简单数论 1)n可能不能为偶数.因为偶数可不可能模上偶数以后==1. 2)n肯定不可能为1 .因为任何数模上1 == ...

  9. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

随机推荐

  1. Mysql存储过程中的事务回滚

    create procedure test(in a int) BEGIN ; ;-- 异常时设置为1 START TRANSACTION; ,); ,); THEN ROLLBACK; ELSE C ...

  2. CyclicBarrier源码分析

    CyclicBarrier是通过ReentrantLock(独占锁)和Condition来实现的.下面,我们分析CyclicBarrier中3个核心函数: 构造函数, await()作出分析. 1. ...

  3. Detecting iOS

    Detecting iOS I am not a fan of User Agent sniffing, but here is how you would do it: var iOS = /iPa ...

  4. poj 3308 Paratroopers(二分图最小点权覆盖)

    Paratroopers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8954   Accepted: 2702 Desc ...

  5. luogu3810 【模板】三维偏序(陌上花开)

    ref1 ref2 ref3 ref4 #include <algorithm> #include <iostream> #include <cstdio> usi ...

  6. mac攻略(八) -- 神器zsh和iterm2的配置

      1. 安装oh my zsh 安装命令: curl -L http://install.ohmyz.sh | sh 修改shell的方式: chsh -s /bin/zsh   2.安装cask( ...

  7. Git之2分钟教程

    Git之2分钟入门 普通人:“借我1000块钱”.程序猿:“借你1024吧,凑个整”. 今天是1024,是我们程序员的节日,在此,首先祝各位程序猿以及程序媛们节日快乐~然后送出一份节日礼物,没错,就是 ...

  8. openpyxl模块介绍

    openpyxl模块是一个读写Excel 2010文档的Python库,如果要处理更早格式的Excel文档,需要用到额外的库,openpyxl是一个比较综合的工具,能够同时读取和修改Excel文档.其 ...

  9. javascript计算两个时间的差

    function GetDateDiff(startTime, endTime, diffType) { //将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式 startTime ...

  10. 【bzoj2406】矩阵 二分+有上下界可行流

    题目描述 输入 第一行两个数n.m,表示矩阵的大小. 接下来n行,每行m列,描述矩阵A. 最后一行两个数L,R. 输出 第一行,输出最小的答案: 样例输入 2 2 0 1 2 1 0 1 样例输出 1 ...