17115 ooxx numbers 交表

17115 ooxx numbers

时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: G++;GCC

Description

a number A called oo number of a number B if the sum of all As factor is the number B.
(A,B) is a pair of ooxx numbers if A is the oo number of B and B is the oo number of A.
Now i want to find how many pairs of ooxx numbers in [1,n]

输入格式

there are many cases in the input.
for each line there is a number n. ( 1 <= n <= 5000000 )

输出格式

for each n, output the numbers of pairs of ooxx numbers in [1,n] 

输入样例

300
1300

输出样例

1
2

提示

hits
220=1+2+4+71+142=284,
284=1+2+4+5+10+11+20+22+44+55+110=220。
220 and 280 is a pair of ooxx numbers.

作者

admin

明显可以用nlogn完成book[i]表示i这个数的所有因子和,然后打表。但是题目还是卡了nlogn。所以就交表。

用pair x y表示他们是同一对生成元,然后保证x是小于y的,(这个在打表的时候可以确保,从小到大枚举,如果有的话,就会先进入了)

然后对y进行前缀和,因为y是大于x的,所以y才是有意义的。就是220和280,问250是没有的,问280才行。

pre[i]表示小于等于i的数字中有多少个答案。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 5000000 + 20;
LL book[maxn];
struct node {
    int x, y;
    bool operator < (const struct node & rhs) const {
        if (x != rhs.x) {
            return x < rhs.x;
        } else return y < rhs.y;
    }
}a[maxn];
int x[maxn] = {0, 220, 1184, 2620, 5020, 6232, 10744, 12285, 17296, 63020, 66928, 67095, 69615, 79750, 100485, 122265, 122368,141664, 142310, 171856, 176272, 185368, 196724, 280540, 308620, 319550, 356408, 437456, 469028, 503056, 522405, 600392, 609928,
624184, 635624, 643336, 667964, 726104, 802725, 879712, 898216, 947835, 998104, 1077890,
1154450, 1156870, 1175265, 1185376, 1280565, 1328470, 1358595, 1392368, 1466150, 1468324, 1511930, 1669910, 1798875, 2082464, 2236570, 2652728, 2723792, 2728726, 2739704, 2802416, 2803580, 3276856, 3606850, 3786904, 3805264, 4238984, 4246130, 4259750};

int y[maxn] = {0, 284, 1210, 2924, 5564, 6368, 10856, 14595, 18416, 76084, 66992, 71145, 87633, 88730, 124155, 139815, 123152,153176, 168730, 176336, 180848, 203432, 202444, 365084, 389924, 430402, 399592, 455344, 486178, 514736, 525915, 669688, 686072, 691256, 712216, 652664, 783556, 796696, 863835, 901424, 980984, 1125765, 1043096, 1099390,
 1189150, 1292570, 1438983, 1286744, 1340235, 1483850, 1486845, 1464592, 1747930, 1749212, 1598470, 2062570,1870245, 2090656, 2429030, 2941672, 2874064, 3077354, 2928136, 2947216, 3716164, 3721544, 3892670, 4300136, 4006736, 4314616, 4488910, 4445050};
int lena = 71;
//bool vis[maxn];
//void init() {
//    for (int i = 1; i <= maxn - 20; ++i) {
//        for (int j = 2 * i; j <= maxn - 20; j += i) {
//            book[j] += i;
//        }
//    }
//    lena = 0;
//    for (int i = 1; i <= maxn - 20; ++i) {
//        if (book[i] <= maxn - 20) {
//            if (!vis[i] && book[book[i]] == i && book[i] != i) {
//                ++lena;
//                a[lena].x = i;
//                a[lena].y = book[i];
//                vis[i] = true;
//                vis[book[i]] = true;
//            }
//        }
//    }
//    sort(a + 1, a + 1 + lena);
//    for (int i = 1; i <= maxn - 20; ++i) {
//        x[i] = a[i].x;
//        y[i] = a[i].y;
//    }
//    for (int i = 1; i <= 10; ++i) {
//        cout << a[i].x << " " << a[i].y << endl;
//    }
//}
int n;
int pre[maxn];
void init() {
    for (int i = 1; i <= lena; ++i) {
        pre[y[i]] = 1;
    }
    for (int i = 1; i <= maxn - 20; ++i) {
        pre[i] += pre[i - 1];
    }
}
void work() {
    printf("%d\n", pre[n]);
}
int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    init();
    while (scanf("%d", &n) != EOF) work();
    return 0;
}

时间: 2024-11-03 22:08:13

17115 ooxx numbers 交表的相关文章

UVA 11582 Colossal Fibonacci Numbers!(打表+快速幂)

Colossal Fibonacci Numbers! The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and f (1) = 1 f (i+2) = f (i+1) + f (i)  for every i ≥ 0 Your task is to compute some values of this sequence. Input begins with an int

HDU 4325 Vampire Numbers 打表

杭电服务器是慢啊.. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <math.h> #include <set> #include <vector> #include <map> using namespace std; #define ll long long #define N

SQL Server -&gt;&gt; 生成Numbers辅助表

if object_id('MyDB.dbo.Numbers') is not null drop table MyDB.dbo.Numbers go use [MyDB] go create table dbo.Numbers(ID INT NOT NULL) go create unique clustered index ix_uniq_clst_numbers_id on dbo.Numbers(id) go with t as ( select row_number() over (o

51nod 1010 只包含因子2 3 5的数 &amp;&amp; poj - 1338 Ugly Numbers(打表)

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先poj这题要找出第n个丑数,想到要打表,因为每一个丑数都是由前一个丑数*2或者*3或者*5得到,每次取3种结果种较小的那一个放入数组中. 打表的时候要注意保持数组有序. 1 #include <iostream> 2 #include <cstdio> 3 #include <c

SpringMVC--提交表单

今天使用AbstractCommandController做一个提交表单的样例 (1)首先,建立一个User.java package com.zk.domain; import java.util.Date; public class User { private Integer id; private String name; private String age; private String birthday; public Integer getId() { return id; }

例题10-7 交表 UVa10820

1.题目描述:点击打开链接 2.解题思路:本题实质上是要求满足1≤x,y≤n,且x,y互素的个数.除了(1,1)外,其余的x,y各不相同.设x<y有f(n)个,那么最终答案是2*f(n)+1.关于f(n)的计算就是不超过n的所有数的欧拉函数的和.而求解1~n中所有数的欧拉函数的时间复杂度是O(N*loglogN). 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #inc

UVA 10820 交表

#include<iostream> #include<string> #include<string> #include<string.h> #include<stdio.h> #include<queue> #include<math.h> #include<vector> #include<stdlib.h> #define maxn 50000 #include<algorithm&g

交表单数据到你的网站,给安全造成了问题

<?php class Crumb { const SALT = 'http:test.com'; static $ttl = 7200; static public function issueCrumb($uid, $ttl=7200, $action= -1) { if(intval($ttl)>7200) self::$ttl = $ttl; $i = ceil(time() / self::$ttl); return substr(self::challenge($i . $acti

HTML表单元素及CSS

表单 一.介绍 <form> 标签表示为表单,表单元素是允许用户在表单中输入内容. 属性:action-提交表单的地址 Method-提交表单的方式.属性值:get/post Enctype-被提交表单的MIME类型 二.表单组件 组件一般被定义在表单中(<form>标签中) <input>标签表示输入框,为空标签. <input> 元素在 <form> 元素中使用,用来声明允许用户输入数据的 input 控件. 属性1:type,type 属性