码迷,mamicode.com
首页 > 其他好文 > 详细

Duff in Love_数论_素因子应用

时间:2016-02-07 02:15:52      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

Duff in Love

TimeLimit:2000MS  MemoryLimit:256MB
64-bit integer IO format:%I64d
Problem Description

Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x.

技术分享

Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovelynumber from his store. He wants this number to be as big as possible.

Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.

Input

The first and only line of input contains one integer, n (1 ≤ n ≤ 1012).

Output

Print the answer in one line.

SampleInput 1
10
SampleOutput 1
10
SampleInput 2
12
SampleOutput 2
6
Note

In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn‘t divisible by any perfect square, so 10 is lovely.

In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 22, so 12 is not lovely, while 6 is indeed lovely.

 

 

按照题意, 获得最大的数, 该数里面没有m*m存在。

转化成获得里面的所有不重复的素因子之积。

除外, 还需优化, 详见注释。

代码:

技术分享
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
ll num, tmp, cnt, i;

int main(void)
{
   scanf( "%I64d", &num );
   cnt = 1;
   for(  i=2; i <= num; ){
      if( !(num%i) ){
         cnt *= i;
// 去除重复素因子
         while( !(num%i) ){
            num/=i;
         }
      }
// 优化, 若 i*i 大于 num, 直接 累乘。
      if( i > sqrt( num ) ){
         cnt *= num;
         break;
      }
      ++ i;
   }
   printf( "%I64d\n", cnt );

   return 0;
}
View Code

 

 

Duff in Love_数论_素因子应用

标签:

原文地址:http://www.cnblogs.com/seana/p/5184430.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!