• JZOJ 5773. 【NOIP2008模拟】简单数学题


    Description

          话说, 小X是个数学大佬,他喜欢做数学题。有一天,小X想考一考小Y。他问了小Y一道数学题。题目如下:
          对于一个正整数N,存在一个正整数T(0<T<N),使得

    的值是正整数。
          小X给出N,让小Y给出所有可能的T。如果小Y不回答这个神奇的大佬的简单数学题,他学神的形象就会支离破碎。所以小Y求你帮他回答小X的问题。
     

    Input

          一个整数N。

    Output

          第一个数M,表示对于正整数N,存在M个不同的正整数T,使得

    是整数。
    后面是M个数,每一个数代表可能的正整数T(按从小到大的顺序排列)。
     

    Sample Input

    Sample Input1:
    1
    
    Sample Input2:
    3
    
    Sample Input3
    180

    Sample Output

    Sample Output
    0
    
    Sample Output
    1 2
    
    Sample Output
    5 120 144 160 168 176
    
     
     

    Data Constraint

          对于5%的数据,N=1.
          对于20%的数据,N<=5.
          对于40%的数据,N<=1000000
          对于另外20%的数据,答案只有1个,且N为质数,保证对于前60%的数据,当N为质数的时候,答案都一定只有一个,对于这20%的数据,满足2<N。
          对于80%的数据,N<=10^9.
          对于100%的数据,N<=10^14.
     
    做法:经过一系列推导

    也就是说,我们要使 是一个正整数,那么我们只需要让(奇数)因数(当然1是不能算的)

    那么,答案为,(其中(num[i])为N的因子)

     代码如下:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <cmath>
     6 #define LL long long
     7 #define N 1000007
     8 using namespace std;
     9 LL n;
    10 LL num[N], ans;
    11 
    12 int main()
    13 {
    14     freopen("math.in", "r", stdin);
    15     freopen("math.out", "w", stdout);
    16     scanf("%lld", &n);
    17     if (n > 5)
    18     {
    19         LL p = sqrt(n);
    20         for (int i = 1; i <= p + 1; i++)
    21             if (n % i == 0)
    22             {
    23                 if (i % 2 != 0 && i != 1)    num[++ans] = i;
    24                 if ((n / i) % 2 != 0)
    25                     num[++ans] = n / i;
    26             }
    27         if (n % p == 0)    num[ans--] = 0;
    28         sort(num + 1, num + ans + 1);
    29         printf("%lld ", ans);
    30         for (int i = 1; i <= ans; i++)
    31         {
    32             LL g = n / num[i];
    33             printf("%lld ", g * (num[i] - 1));
    34         }
    35     } 
    36     else
    37     {
    38         if (n == 3)
    39             printf("1 2");
    40         else if (n == 5)
    41             printf("1 4");
    42         else printf("0");
    43     }
    44 }
    View Code
  • 相关阅读:
    《分析的艺术》读书笔记
    MySql数据库文件frm的移植
    R语言学习笔记(一)
    GATE使用笔记(使用自带的GUI界面)
    如何解决 Endnote自动搜索word中中括号[ ]或者大括号{}内的文字
    java import中jar包的位置
    hello
    filebeatkafkaelk搭建
    android note3
    iOS 6 SDK: 在应用内展示App Store
  • 原文地址:https://www.cnblogs.com/traveller-ly/p/9461226.html
Copyright © 2020-2023  润新知