• Uva 11395 Sigma Function (因子和)


    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/C   题目在文末

    题意:1~n (n:1~1012)中,因子和为偶数的有几个。
    题解:

    因子和 Sum=(p1^0+p1^1….p1^e1)*(p2^0+p2^1…p2^e2)……(pn^0+…pn^en); 

    =

    clip_image002

    (p1^0+p1^1….p1^e1),(p2^0+p2^1…p2^e2),……(pn^0+…pn^en)中只要有一个是偶数,因子和sum就为偶数。所以只要找到一个是偶数就可以了。 

    若pi为偶数,则pi^x(x>0)为偶数,而pi^0=1(1+偶+偶….为奇数)。So,(pi^0+pi^1+…pi^ei)为奇数。所以pi只能是奇数,才能使(pi^0+pi^1+…pi^ei)为偶数。

    再看pi^x (若x为奇数,pi^x为奇数(奇*奇*…为奇)),So,(pi^0+pi^1+…pi^ei)为偶数(1+奇+奇…)

    所以,对m素因子分解,只要存在一个pi,ei都为奇数的pi^ei,就能使sum为偶数。

    然而这么做必定TLE(-。-;)

    再想想,1~n中 有多少个的素因子分解中存在pi^ei(奇^奇)。

    3^(2k-1)  *  (1,2,3,4..n/3)          (k>1&&3^(2k-1)<=n)

    5^(2k-1)  *  (1,2,3,4…n/5)  

    ….

    prime[i]^(2k-1)  *  (1,2,3,…n/prime[i])  能包含所有的解,然而还有好多重复的解。看着有点像容斥定理,但多了个条件。(prime[i]^1,prime[i]^3…容斥有问题)。想了好久,感觉这题好难,不会了。。

    不会咋办,换个思路呗!

    不过之前还是忍不住暴力了一下 果断TLE

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 using namespace std;
     5 const int N=1e6+5;
     6 
     7 bool vis[N];
     8 int prime[N],cnt;
     9 void is_prime()
    10 {
    11     cnt=0;
    12     memset(vis,0,sizeof(vis));
    13     for(int i=2;i<N;i++)
    14     {
    15         if(!vis[i])
    16         {
    17             prime[cnt++]=i;
    18             for(int j=i+i;j<N;j+=i)
    19                 vis[j]=1;
    20         }
    21     }
    22 }
    23 
    24 bool is_even(long long n)
    25 {
    26     for(int i=0;i<cnt&&prime[i]*prime[i]<=n;i++)
    27     {
    28         int count=0;
    29         if(n%prime[i]==0)
    30         {
    31             while(n%prime[i]==0)
    32             {
    33                 n/=prime[i];
    34                 count++;
    35             }
    36             if(prime[i]&1)
    37             {
    38                 if(count&1)
    39                     return true;
    40             }
    41         }
    42     }
    43     if(n>1&&(n&1))
    44         return true;
    45     return false;
    46 }
    47 
    48 int main()
    49 {
    50     int t;
    51     cin>>t;
    52     is_prime();
    53     for(int kase=1;kase<=t;kase++)
    54     {
    55         long long n;
    56         cin>>n;
    57         long long count=0;
    58         for(long long i=1;i<=n;i++)
    59         {
    60             if(is_even(i))
    61                 cout<<i<<endl;
    62                 count++;
    63         }
    64         printf("Case %d: %d
    ",kase,count);
    65     }
    66 }

    反过来想,什么时候因子和是奇数呢?
    由前面的分析(只要存在一个pi,ei都为奇数的pi^ei,就能使sum为偶数),素因子分解后,全为奇^偶,偶^偶,偶^奇,因子和就是奇数。

    2是唯一一个偶素数。(特别的就得拿出来分开考虑。。)

    ((数^(偶/2)*(数^(偶/2))....)^2,这不是平方数吗!(数指的是奇数||偶数) (包含了数^偶

    所以这些数是 平方数 || 2*平方数 。(想不通的可以拿奇^偶,偶^偶,偶^奇组合,发现全被 平方数 || 2*平方数 包含了)

    #include<iostream>
    #include<cmath>
    #include<cstdio>
    using namespace std;
    typedef long long LL;
    
    int main()
    {
        int t;
        scanf("%d",&t);
        for(int kase=1;kase<=t;kase++)
        {
            LL n;
            scanf("%lld",&n);
            LL num1=(LL)sqrt((double)n);
            LL num2=(LL)sqrt((double)n/2.0);
            printf("Case %d: %lld
    ",kase,n-num1-num2);
        }
        return 0;
    }

    一开始说好的题目 (-。-;)

    Sigma Function

    Description

    Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes the sum of all divisors of a number. For example σ(24) = 1+2+3+4+6+8+12+24=60. Sigma of small numbers is easy to find but for large numbers it is very difficult to find in a straight forward way. But mathematicians have discovered a formula to find sigma. If the prime power decomposition of an integer is

    Then we can write,

    For some n the value of σ(n) is odd and for others it is even. Given a value n, you will have to find how many integers from 1 to n have even value ofσ.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing an integer n (1 ≤ n ≤ 1012).

    Output

    For each case, print the case number and the result.

    Sample Input

    4

    3

    10

    100

    1000

    Sample Output

    Case 1: 1

    Case 2: 5

    Case 3: 83

    Case 4: 947

  • 相关阅读:
    ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值
    ORA-01033: ORACLE initialization or shutdown in progress
    Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
    java.sql.SQLException: ORA-28001: the password has expired。
    ORA-00928: 缺失 SELECT 关键字
    针对不同浏览器的页面关闭
    bootstrap-datetimepicker 时间表箭头不能显示
    get方式请求会出现中文乱码。post方式不会。
    文件上传
    BZOJ1001 [Beijing2006]狼抓兔子
  • 原文地址:https://www.cnblogs.com/shentr/p/5285134.html
Copyright © 2020-2023  润新知