Problem - D - Codeforces

题意:问能否在进行K次操作的情况下,将两个数变得相同,操作为每次选择一因子,然后除该因子。

题解:要判断该数最多能进行几次除的操作,其实就是判断这个数有多少个质因子,然后判断最后最多进行的操作数和要求的操作数大小关系,其中K=1的时候要特判一下。

  • 其中开始的时候一直TLE,后来发现是long long 的问题,在没必要的情况下, long long的运行速度是慢与int的,这会在数据多的时候TLE。

详情可见  performance - C++ int vs long long in 64 bit machine - Stack Overflow

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=1e6+10;
const ll inf=1e15;
signed main(){
int n;scanf("%d",&n);
while(n--){
int x,y,w;scanf("%d %d %d",&x,&y,&w);
if(w==1){
puts((x%y==0||y%x==0)&&x!=y?"YES":"NO");//只有当一个数是另一个数的因子,才可以
continue;
}
for(int i=2;i*i<=x;i++){
if(x%i==0){
while(x%i==0){
x/=i;w--;
}
}
}
if(x>1) w--;
if(w<=0){
printf("Yes\n");continue;
}
for(int i=2;i*i<=y;i++){
if(y%i==0){
while(y%i==0){
y/=i;w--;
}
}
}
if(y>1) w--;
puts(w>0?"NO":"YES");
}
}

CF-D. Another Problem About Dividing Numbers的更多相关文章

  1. 【Leetcode_easy】728. Self Dividing Numbers

    problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...

  2. 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...

  3. [LeetCode&Python] Problem 728. Self Dividing Numbers

    A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...

  4. #452 Div2 Problem C Dividing the numbers ( 思维 || 构造 )

    题意 : 将从 1 ~ n 的数分成两组,要求两组和的差值尽可能小,并输出其中一组的具体选数情况 分析 : 如果将这 n 个数从大到小四个一组来进行选择的话那么差值就为 0 ,然后再来考虑 n%4 ! ...

  5. Codeforces CF#628 Education 8 D. Magic Numbers

    D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  7. java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版

    1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its digits consists of o ...

  8. cf C. Tourist Problem

    http://codeforces.com/contest/340/problem/C #include <cstdio> #include <cstring> #includ ...

  9. CF 291E. Tree-String Problem [dfs kmp trie图优化]

    CF291E 题意:一棵树,每条边上有一些字符,求目标串出现了多少次 直接求目标串的fail然后一边dfs一边跑kmp 然后就被特殊数据卡到\(O(n^2)\)了... 因为这样kmp复杂度分析的基础 ...

随机推荐

  1. 《原CSharp》第二回 巧习得元素分类 子不知怀璧其罪

    第二回 巧习得元素分类 子不知怀璧其罪 ===================================================================== 云溪父亲见状看了看云 ...

  2. ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)

    一.说明 主要是对字符串的字段进行hash取模 二.修改配置文件config-sharding.yaml,并重启服务 # # Licensed to the Apache Software Found ...

  3. BUUCTF-qr

    qr 签到题

  4. Python量化-如何获取实时股票信息

    如何获取实时股票信息 股票信息的接口有很多,之前大家常用的是新浪的,但在年初的时候,新浪的接口突然不能使用,给大家造成了很大的困扰,为此网上也有很多教程教大家如何从新浪获取数据,跟着教程弄了半天也不行 ...

  5. ssh-修改ssh服务端口号

    在启动selinux的状态下修改ssh的端口号 0.启动selinux     setenforce 1     getenforce 1.修改sshd_config的Port为2234 查看2234 ...

  6. 人人都能学会的 Python 多线程指南~

    大家好鸭!有没有想我~(https://jq.qq.com/?_wv=1027&k=rX9CWKg4) 在 Python 中,多线程最常见的一个场景就是爬虫,例如这样一个需求,有多个结构一样的 ...

  7. NC16430 [NOIP2016]蚯蚓

    NC16430 [NOIP2016]蚯蚓 题目 题目描述 本题中,我们将用符号 \(\lfloor c \rfloor\) 表示对 c 向下取整,例如:\(\lfloor 3.0 \rfloor = ...

  8. NC201605 Bits

    NC201605 Bits 题目 题目描述 Nancy喜欢做游戏! 汉诺塔是一个神奇的游戏,神奇在哪里呢? 给出 \(3\) 根柱子,最开始时 \(n\) 个盘子按照大小被置于最左的柱子. 如果盘子数 ...

  9. .NET服务治理之限流中间件-FireflySoft.RateLimit

    概述 FireflySoft.RateLimit自2021年1月发布第一个版本以来,经历了多次升级迭代,目前已经十分稳定,被很多开发者应用到了生产系统中,最新发布的版本是3.0.0. Github:h ...

  10. 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架

    什么是Scrapy 基于Twisted的异步处理框架 纯python实现的爬虫框架 基本结构:5+2框架,5个组件,2个中间件 5个组件: Scrapy Engine:引擎,负责其他部件通信 进行信号 ...