Codeforces 371B Fox Dividing Cheese(简单数论)
题目链接 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(简单数论)的更多相关文章
- 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); ...
- CF 371B Fox Dividing Cheese[数论]
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
- 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 ...
- cf B. Fox Dividing Cheese
http://codeforces.com/contest/371/problem/B #include <cstdio> #include <iostream> #inclu ...
- Codeforces - 773A - Success Rate - 二分 - 简单数论
https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...
- Codeforces - 346A - Alice and Bob - 简单数论
http://codeforces.com/problemset/problem/346/A 观察了一下,猜测和他们的最大公因数有关,除以最大公因数前后结果是不会变的. 那么怎么证明一定是有n轮呢?我 ...
- (step7.2.1)hdu 1395(2^x mod n = 1——简单数论)
题目大意:输入一个整数n,输出使2^x mod n = 1成立的最小值K 解题思路:简单数论 1)n可能不能为偶数.因为偶数可不可能模上偶数以后==1. 2)n肯定不可能为1 .因为任何数模上1 == ...
- Codeforces 828B Black Square(简单题)
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...
随机推荐
- 自定义View/ViewGroup的步骤和实现
1.设置属性(供XML调用) 在res目录新建attrs.xml文件 <?xml version="1.0" encoding="utf-8"?> ...
- Service IntentService区别 (面试)
依然记得自己当初没有真正的工作经验的时候的日子,满北京跑,没有人要.妈的,现在就想问,还有谁!想想真解气.不提了. 曾经有个面试官问我service 和IntentService的区别.当时自己模模糊 ...
- appcompat_v7\res\values-v21\themes_base.xml:158: error: Error: No resource
C:\DevelopSoft\workspace\appcompat_v7\res\values-v21\themes_base.xml:158: error: Error: No resource ...
- 网络抢票黄牛,大部分是骗人的。公布一个骗钱黄牛,QQ:2233261390,QQ群:29443597,支付页面:https://me.alipay.com/q336
想着给女友买张回广州的回程火车票,抢了3天也没弄到.情急之下找了网络上所谓的黄牛.结果上当受骗.具体经过是这样的: 对方承诺抢到再付款.于是等他抢到后截图给我看,而且可以远程到他的机器去看,我也确实远 ...
- loj2073 「JSOI2016」扭动的回文串
ref 主要是要理解"撑到"最长这个概念 (为啥我的代码这么长QAQ #include <iostream> #include <cstdio> using ...
- leetcode 【 Trapping Rain Water 】python 实现
题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...
- MFC深入浅出读书笔记第一部分
最近看侯捷的MFC深入浅出,简单总结一下. 第一章首先就是先了解一下windows程序设计的基础知识,包括win32程序开发基础,什么*.lib,*.h,*.cpp的,程序入口点WinMain函数,窗 ...
- Html语言的标签讲解
一.head头部中的内容: 1.<meta charset="UTF-8"> <--!告诉浏览器什么编码--> 2.<meta http-equiv= ...
- Android数据储存之File
openFileOutStream 和 openFileInStream FileInputStream fileInputStream = openFileInput(name); 打开应用下文件 ...
- [HDU3516] Tree Construction [四边形不等式dp]
题面: 传送门 思路: 这道题有个结论: 把两棵树$\left[i,k\right]$以及$\left[k+1,j\right]$连接起来的最小花费是$x\left[k+1\right]-x\left ...