Uva 11395 - Sigma Function 规律 对数

来源:互联网 发布:python argparse 编辑:程序博客网 时间:2024/05/22 05:21
/**  规律:通过打表后发现,在n的范围内,只有2^x 以及 平方数 和 平方数的2倍符合要求。*    即:2^1, 2^2,...   1*1, 2*2,...    2*1*1, 2*2*2, 2*3*3... 等等,故只要去重就可以了*  url: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2390*  stratege: 规律,对数*  Author: Johnsondu*/#include <iostream>#include <cmath>#include <cstdio>#include <cstring>using namespace std;#define LL long long LL n, t1, t2, t3, t4, t5, t6 ;int main (){int tcase, cas = 1 ;scanf ("%d", &tcase) ;while (tcase --){scanf ("%lld", &n) ;if (n == 1){    printf ("Case %d: 0\n", cas++) ;    continue ;}t1 = (LL)sqrt (n*1.0) ;             //一共有t1^2 < n, 故有t1 个t2 = (LL)(log(n*1.0) / log(2.0)) ;  // 2^t2 内, 有t2个t3 = ((LL)(log(n*1.0) / log(2.0)) - 1) / 2 + 1 ;  // 2*x*x与2^t2中,与2^3, 2^7,...,重复t4 = (LL)sqrt (n/2.0) ;  // 2*x*x一共有t4个t5 = (LL) (log(t1*1.0)/log(2.0)) ;  //t1中x*x 与 2^t2重复的有t5个printf ("Case %d: %lld\n", cas++, n - (t1 - t5 + t2 + t4 - t3)) ;}return 0 ;}/*打表的代码:#include <iostream>#include <cmath>#include <cstdio>#include <cstring>using namespace std;#define LL long long #define MAXN 33000int p[MAXN] ;bool isPrime[MAXN];int prilen, a, b ;void getPrime (){int i ;for (i = 0; i < MAXN; i ++){isPrime[i] = true ;}for (i = 4; i < MAXN; i += 2)isPrime[i] = false ;p[0] = 2 ;prilen = 1 ;for (i = 3; i < MAXN; i += 2){if (isPrime[i]){int tmp = 2 * i ;p[prilen ++] = i ;while (tmp < MAXN){isPrime[tmp] = false ;tmp += i ;}}}}int get (int n){int ans = 1 ;int t = n ;for (int i = 0; p[i]*p[i] <= t; i ++){if (t % p[i] == 0){int num = 0 ;while (t % p[i] == 0){num ++ ;t/=p[i] ;}ans = ans * ((int)pow(p[i]*1.0, num+1.0) - 1) / (p[i]-1) ;}}if (t > 1)ans = ans * ((int)pow(t*1.0, 2.0)-1)/(t-1) ;return ans ;}int main (){getPrime () ;//int ans = 0 ;for (int i = 1; i <= 1000; i ++){//printf ("%d -- %d\n", i, get(i)) ;if (get(i) % 2 != 0)printf ("%d --- %d\n", i, get(i)) ;}return 0 ;}1 --- 12 --- 34 --- 78 --- 159 --- 1316 --- 3118 --- 3925 --- 3132 --- 6336 --- 9149 --- 5750 --- 9364 --- 12772 --- 19581 --- 12198 --- 171100 --- 217121 --- 133128 --- 255144 --- 403162 --- 363169 --- 183196 --- 399200 --- 465225 --- 403242 --- 399256 --- 511288 --- 819289 --- 307324 --- 847338 --- 549361 --- 381392 --- 855400 --- 961441 --- 741450 --- 1209484 --- 931512 --- 1023529 --- 553576 --- 1651578 --- 921625 --- 781648 --- 1815676 --- 1281722 --- 1143729 --- 1093784 --- 1767800 --- 1953841 --- 871882 --- 2223900 --- 2821961 --- 993968 --- 1995*/

原创粉丝点击