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. ...
随机推荐
- 【转】Python操作MongoDB
Python 操作 MongoDB 请给作者点赞--> 原文链接 这篇文章主要介绍了使用Python脚本操作MongoDB的教程,MongoDB作为非关系型数据库得到了很大的宣传力度,而市面 ...
- eclipse 插件,直接打开文件路径
https://github.com/samsonw/OpenExplorer/downloads 22k的小插件,意义却重大.下载之后,放到plugins里面.
- leetcode 【 Remove Element 】python 实现
题目: Given an array and a value, remove all instances of that value in place and return the new lengt ...
- Leetcode 576.出界的路劲数
出界的路径数 给定一个 m × n 的网格和一个球.球的起始坐标为 (i,j) ,你可以将球移到相邻的单元格内,或者往上.下.左.右四个方向上移动使球穿过网格边界.但是,你最多可以移动 N 次.找出可 ...
- 查找jar包中.class文件关键字(变量名,字符串)
有时查看日志,常常会发现由框架底层打印的错误日志.要修改这个错误的时候,如果不是对框架特别熟悉,就需要按照可能产生这个错误日志的流程一步一步找,一时半会不一定能找到.比如本人最近对smartfoxse ...
- mysql-Innodb事务隔离级别-repeatable read详解
http://blog.csdn.net/dong976209075/article/details/8802778 经验总结: Python使用MySQLdb数据库后,如使用多线程,每个线程创建一个 ...
- 关于在smarty中实现省市区三级联动
刚开始接触php,,其实对于一些比较深入的东西还不是很了解,就像是这次的省市区联动,都是用三张表为基础编码的,原谅我的无知,谢谢. 接下来就是编码部分了: <?php require('./sm ...
- 谈谈Python中元类Metaclass(二):ORM实践
什么是ORM? ORM的英文全称是“Object Relational Mapping”,即对象-关系映射,从字面上直接理解,就是把“关系”给“对象”化. 对应到数据库,我们知道关系数据库(例如Mys ...
- iOS开发UI篇—自定义layer
一.第一种方式 1.简单说明 以前想要在view中画东西,需要自定义view,创建一个类与之关联,让这个类继承自UIView,然后重写它的DrawRect:方法,然后在该方法中画图. 绘制图形的步骤: ...
- httpClient get方式抓取数据
/* * 爬取网页信息 */ private static String pickData(String url) { CloseableHttpClient ht ...