Codeforces 371B Fox Dividing Cheese(简单数论)
2024-10-15 18:48:01
题目链接 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 ; }
最新文章
- BZOJ 1060: [ZJOI2007]时态同步
- PS通过滤色实现简单的图片拼合
- 说下查询动作 Pivot
- Windows 7 下如何设置机器级别的DCOM权限
- G面经prepare: Reorder String to make duplicates not consecutive
- 【宋红康学习日记1】关于环境变量设置出现的问题——找不到或无法加载主类 java
- stdafx.h的作用以及原理
- 在ubuntu12.04下编译android4.1.2添加JNI层出现问题
- PLSQL 循环示例
- Cross Product
- pcommlite串口通讯库使用
- JS中的phototype JS的三种方法(类方法、对象方法、原型方法)
- 【Gradle】Gradle环境配置
- ";当前不会命中断点,没有与此行关联的可执行代码";可能和";断点位置不准确";有关
- python学习 day014打卡 内置函数二&;递归函数
- python print 使用分隔符 或行尾符
- W1002 Symbol &#39;Create&#39; is specific to a platform
- dubbo实际应用中的完整的pom.xml
- 【Python】Python 微服务框架 nameko
- ubuntu16.04下ftp服务器的安装与配置