LightOJ1336 Sigma Function 素因子分解深入理解

来源:互联网 发布:tech域名不能备案 编辑:程序博客网 时间:2024/05/19 01:58
  1. 只有奇数乘奇数才是奇数,而如果使式子为奇数,只能是2的所有次数或者其他素数的偶数次。
  2. 素数的次数的任意组合小于等于n的个数有n个,因为每一个数都可以素因子分解成不同的组合。
  3. 所以奇数有两类,a^2 <= n,或者2是奇数次,2*a^2 <= n,而a就是符合情况的所有组合。

题目链接:http://acm.hust.edu.cn/vjudge/problem/27044

#include<cstdio>#include<iostream>#include<sstream>#include<cstdlib>#include<cmath>#include<cctype>#include<string>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<set>#include<map>#include<ctime>#include<vector>#include<fstream>#include<list>using namespace std;#define ms(s) memset(s,0,sizeof(s))typedef unsigned long long ULL;typedef long long LL;const int INF = 0x3fffffff;LL n,ans;int main(){//    freopen("F:\\input.txt","r",stdin);//    freopen("F:\\output.txt","w",stdout);//    ios::sync_with_stdio(false);    int t;    scanf("%d",&t);    for(int cas = 1; cas <= t; ++cas){        scanf("%lld",&n);        ans = n - (LL)sqrt(n) - (LL)sqrt(n/2);        printf("Case %d: %lld\n",cas,ans);    }    return 0;}
1 0
原创粉丝点击