zoukankan      html  css  js  c++  java
  • Codeforces Round #326 (Div. 2) B

    1.每一个合数都可以由若干个素数相乘而得到
    2.质因数知识 :求一个数因数的个数等于它的每个质因数的次数加一的和相乘的积
    因为质因数可以不用,所以要加一.
    例如6=2x3,两个质因数都是一次,如果两个质因数都不用,它的一个因数是1;只用因数2,它的第二个因数就是2;只用因数3,它的第三个因数就是3;两个质因数都用,它的第四个因数就是6。
    所以6的因数的个数就是(1+1)(1+1)=4。
    再如12=2²x3,两个质因数,2是2次,3是一次,如果两个质因数都不用,它的一个因数是1;只用一个因数2,它的第二个因数就是2;两个2都用,它的第三个因数就是4;不用3时就有3个因数,再用上3时就是(2+1)(1+1)=6个因数了。
    然后下面这道题的答案就是每个质因数都只乘一次     10就是2x5。12就是2x3。
    B. Duff in Love
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 lovely number 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.

    Examples
    input
    10
    output
    10
    input
    12
    output
    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.

    AC代码

     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 #include <iostream>
     6 #include <sstream>
     7 #include <algorithm>
     8 #include <string>
     9 #include <queue>
    10 #include <vector>
    11 using namespace std;
    12 const int maxn= 510;
    13 const int maxm= 1e4+10;
    14 const int inf = 0x3f3f3f3f;
    15 typedef long long ll;
    16 int main()
    17 {
    18     ll n;
    19     while(scanf("%I64d",&n)!=EOF)   //codeforces 不支持%lld
    20     {
    21         ll sum=1;
    22         for(int i=2;i<=sqrt(n);i++)     //要用sqrt函数 用i*i<=n 要把i定义为ll i*i会爆int
    23         {
    24             if(n%i==0)
    25                 sum*=i;
    26             while(n%i==0)          //除去倍数
    27                 n/=i;
    28         }
    29         printf("%I64d
    ",sum*n);
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    php连接mysql数据库
    关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread
    mac“打不开身份不明的开发者”
    微信小程序开发warning: Now you can provide attr "wx:key" for a "wx:for" to improve performance
    将任何GitHub内的代码转为外部CDN网址
    把自己的代码发布到npm(npm publish)
    wordpress写文章添加gif图片变成静态图片的解决办法
    canvas实现刮刮乐
    api文档管理系统合集
    niubi-job:一个分布式的任务调度框架设计原理以及实现
  • 原文地址:https://www.cnblogs.com/stranger-/p/7751801.html
Copyright © 2011-2022 走看看