http://lightoj.com/volume_showproblem.php?problem=1220

题目大意: 给你一个x,求出满足 x=b^p, p最大是几。

分析:x=p1^a1*p2^a2*...*pn^an;

p最大是gcd(a1,a2,...,an)。

///他该诉你x,b,p都是整数,所以x,b有可能是负数。当x是负数时,p不能是偶数。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue> using namespace std;
typedef long long LL;
#define N 100000
#define ESP 1e-8
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a)) LL prime[N], k;
bool vis[N]; void Prime()
{
memset(vis, false);
k = ;
for(int i=; i<N; i++)
{
if(vis[i] == )
{
prime[k ++] = i;
for(int j=i+i; j<N; j+=i)
{
vis[j] = ;
}
}
}
} LL gcd(LL a, LL b)
{
LL r;
while(b)
{
r = a%b;
a = b;
b = r;
}
return a;
} LL solve(LL n)
{
LL ans, sum;
ans = ;
sum = ;
int flag = ; for(int i=; prime[i]*prime[i] <= n; i++)
{
if(n%prime[i] == )
{
ans = ;
while(n%prime[i] == )
{
n /= prime[i];
ans ++;
}
if(flag == )
{
sum = ans;
flag = ;
}
else if(flag == )
sum = gcd(sum, ans);
}
}
if(n>)
sum = ; return sum;
} int main()
{
int T, t=;
Prime();
scanf("%d", &T);
while(T --)
{
LL n;
scanf("%lld", &n); int b = ; if(n<)
{
n = -n;
b = ;
} LL sum = solve(n); if(b == && sum% == )
{
while(sum% == )
sum/=;
}
printf("Case %d: %lld\n", t++, sum);
}
return ;
}

1220 - Mysterious Bacteria--LightOj1220 (gcd)的更多相关文章

  1. LightOJ 1220 Mysterious Bacteria(唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1220 Mysterious Bacteria Time Limit:500MS     Memo ...

  2. LightOj 1220 - Mysterious Bacteria (分解质因子x=b^p 中的 x 求最大的 p)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1220 题意:已知 x=bp 中的 x 求最大的 p,其中 x b p 都为整数 x = ...

  3. LightOj 1220 Mysterious Bacteria

    题目大意: 给出一个x,求满足x = b^p,p最大是多少? 解题思路: x可以表示为:x = p1^e1 * p2^e2 * p3^e3 ....... * pn^en. p = gcd (e1,e ...

  4. LightOJ 1220 Mysterious Bacteria 水题

    暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...

  5. LightOJ-1220 Mysterious Bacteria 唯一分解定理 带条件的最大公因数

    题目链接:https://cn.vjudge.net/problem/LightOJ-1220 题意 给x=y^p,问p最大多少 注意x可能负数 思路 唯一分解定理,求各素因数指数的GCD 注意负数的 ...

  6. Mysterious Bacteria LightOJ - 1220

    题意: 给出一个数x 求 x = bp  的p的最大值 解析: 算术基本定理 分解质因数 任何一个数x都可以表示为  x == p1a1   *  p2a2  *  ````` * pnan 即  b ...

  7. LightOJ1220 —— 质因数分解

    题目链接:https://vjudge.net/problem/LightOJ-1220 1220 - Mysterious Bacteria    PDF (English) Statistics ...

  8. LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria

    题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...

  9. [kuangbin带你飞]专题十四 数论基础

            ID Origin Title   111 / 423 Problem A LightOJ 1370 Bi-shoe and Phi-shoe   21 / 74 Problem B ...

随机推荐

  1. Content has been consumed

    if(response.getEntity() != null && response.getEntity().getContent() != null) { message = IO ...

  2. bootstrap--小李子demo

    最近忙啊...看到各位冬鞋都在认真写博客,认真敲代码,认真工作,总觉得自己时间太少,总觉得时间不够,老了...... 进正题: 上次不知从哪里(忘了)下载了bootstrap的一些使用小demo,以后 ...

  3. c语言,检测一个无符号整数中是否有偶数位个1

    最近在学习大牛Bryant O'Hallaron 的深入理解计算机系统,发现学了这么久的程序设计,其实有些基本的东西还不太了解,这不,这两天在恶补整数,浮点数在计算机中的表示,并且开始做上面的习题, ...

  4. ListView下拉刷新

    本内容为复制代码: 一.自定义ListView控件: package com.xczl.smart.view; import java.util.Date; import com.suliang.R; ...

  5. Python学习之路——基础篇(1)字符串格式化

    字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式  百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存. 百分号方式 ...

  6. .NET重载运算符

    代码如下: /// <summary> /// 坐标(结构类型) /// </summary> public struct Coordinate { public int x; ...

  7. call

    -------siwuxie095 call 调用另一个批处理程序或自身程序段,调用完,程序会回到原来 call 的地方继续执行 如果在脚本或批处理文件外使用 call,则不会在命令行起作用 语法 c ...

  8. Java泛型 E、T、K、V、N

    中的标记符含义: E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Number(数值类型) ...

  9. L440 无线网卡:由于该设备有问题,Windows 已将其停止(代码 43)

    最近重装了系统,本来用的好好的,结果重启之后突然无线网卡不能用了,设备管理器老是黄色叹号!无线网卡设备状态:由于该设备有问题,Windows 已将其停止. (代码 43).      无线网卡型号:2 ...

  10. easyui的getRows和appendRow方法使用结果记录

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...