zoukankan      html  css  js  c++  java
  • ural 1355. Bald Spot Revisited

    1355. Bald Spot Revisited

    Time limit: 1.0 second
    Memory limit: 64 MB
     
    A student dreamt that he walked along the town where there were lots of pubs. He drank a mug of ale in each pub. All the pubs were numbered with positive integers and one could pass from the pub number n to the pub with a number that divides n. The dream started in the pub number a. The student knew that he needed to get to the pub number b. It’s understood that he wanted to drink on the way as much ale as possible. If he couldn’t get from the pub number a to the pub number b he woke up immediately in a cold sweat.

    Input

    The first line contains an integer T — an amount of tests. Then T lines with integers a and b follow (0 ≤ T ≤ 20; 1 ≤ a, b ≤ 109).

    Output

    For each test in a separate line you are to output the maximal number of mugs that the student could drink on his way.

    Sample

    inputoutput
    5
    30 89
    2 16
    3 243
    1 1
    2 2
    
    0
    4
    5
    1
    1
    

    Problem Author: Aleksandr Bikbaev
    Problem Source: USU Junior Championship March'2005

    题目大意:a每次乘一个x,求一个最长的次数,使a*x1*x2*x3*x4 。。。。= b

    思路:如果b不能整除a, 输出0;

       否则从从2 开始暴力算

     1 #include <iostream>
     2 #include <sstream>
     3 #include <fstream>
     4 #include <string>
     5 #include <vector>
     6 #include <deque>
     7 #include <queue>
     8 #include <stack>
     9 #include <set>
    10 #include <map>
    11 #include <algorithm>
    12 #include <functional>
    13 #include <utility>
    14 #include <bitset>
    15 #include <cmath>
    16 #include <cstdlib>
    17 #include <ctime>
    18 #include <cstdio>
    19 #include <cstring>
    20 #define FOR(i, a, b)  for(int i = (a); i <= (b); i++)
    21 #define RE(i, n) FOR(i, 1, n)
    22 #define FORP(i, a, b) for(int i = (a); i >= (b); i--)
    23 #define REP(i, n) for(int i = 0; i <(n); ++i)
    24 #define SZ(x) ((int)(x).size )
    25 #define ALL(x) (x).begin(), (x.end())
    26 #define MSET(a, x) memset(a, x, sizeof(a))
    27 using namespace std;
    28 
    29 
    30 typedef long long int ll;
    31 typedef pair<int, int> P;
    32 int read() {
    33     int x=0,f=1;
    34     char ch=getchar();
    35     while(ch<'0'||ch>'9') {
    36         if(ch=='-')f=-1;
    37         ch=getchar();
    38     }
    39     while(ch>='0'&&ch<='9') {
    40         x=x*10+ch-'0';
    41         ch=getchar();
    42     }
    43     return x*f;
    44 }
    45 const double pi=3.14159265358979323846264338327950288L;
    46 const double eps=1e-6;
    47 const int mod = 1e9 + 7;
    48 const int INF = 0x3f3f3f3f;
    49 const int MAXN = 9000005;
    50 const int xi[] = {0, 0, 1, -1};
    51 const int yi[] = {1, -1, 0, 0};
    52 int prime[MAXN], cnt;
    53 bool a[MAXN];
    54 
    55 int main() {
    56     //freopen("in.txt", "r", stdin);
    57 
    58     int t;
    59     scanf("%d", &t);
    60     while(t--) {
    61         int a, b, res = 0, k;
    62         scanf("%d%d", &a, &b);
    63         if(b%a == 0 && b >= a) {
    64             res++;
    65             k = b/a;
    66             for(int i = 2; i*i <=k  && k > 1; i++) {
    67                 while(k%i == 0) {
    68                    // printf("%d ", i);
    69                     k /= i;
    70                     res++;
    71                 }
    72             }
    73             if(k > 1) res++;
    74         }
    75         printf("%d
    ", res);
    76     }
    77     return 0;
    78 }
  • 相关阅读:
    使用Java实现对MySql数据库的导入与导出
    【转】揭开J2EE集群的神秘面纱
    Memcached深度分析
    HSQL入门及使用指南
    系统架构基础篇(高性能基础建设说明与选型条件)
    架构之美 摘抄
    JMS规范及相关实现
    spring3中使用@value注解获取属性值
    Thread Dump 分析综述
    什么中间件及中间件服务器?
  • 原文地址:https://www.cnblogs.com/cshg/p/5893133.html
Copyright © 2011-2022 走看看