Easy Number Challenge(暴力,求因子个数)

Easy Number Challenge

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 236B

Appoint description: 
System Crawler  (2016-04-26)

Description

Let‘s denote d(n) as the number of divisors of a positive integer n. You are given three integers ab and c. Your task is to calculate the following sum:

Find the sum modulo 1073741824(230).

Input

The first line contains three space-separated integers ab and c (1 ≤ a, b, c ≤ 100).

Output

Print a single integer — the required sum modulo 1073741824(230).

Sample Input

Input

2 2 2

Output

20

Input

5 6 7

Output

1520

Hint

For the first example.

  • d(1·1·1) = d(1) = 1;
  • d(1·1·2) = d(2) = 2;
  • d(1·2·1) = d(2) = 2;
  • d(1·2·2) = d(4) = 3;
  • d(2·1·1) = d(2) = 2;
  • d(2·1·2) = d(4) = 3;
  • d(2·2·1) = d(4) = 3;
  • d(2·2·2) = d(8) = 4.

So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20.

题解:

d(x)代表x的因子的个数;还好i,j,k都不大,100,暴力就行,直接由于因子个数等于质因子的系数加一之积,反素数讲过,由此可得;

代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<set>
#define ll long long
#define MOD 1073741824
using namespace std;
int num[110];
int main()
{
    int a,b,c;
    int i,j,k;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        memset(num, 0, sizeof(num));
        ll sum=0, temp;
        set<int>st;
        set<int>::iterator iter;
        for(i=1;i<=a;i++)
        {
            for(j=1;j<=b;j++)
            {
                for(k=1;k<=c;k++)
                {
                temp = i * j * k;
                ll cnt = 1;
                for(int p = 2; p <= temp; p++){
                    if(temp % p == 0){
                        int cur = 0;
                        while(temp % p == 0){
                            temp /= p;
                            cur++;
                        }
                        cnt *= cur + 1;
                    }
                }
                sum += cnt;
                sum %= MOD;
                }
                }
            }

        printf("%lld\n",sum);
    }
    return 0;
}
时间: 2024-10-10 16:10:02

Easy Number Challenge(暴力,求因子个数)的相关文章

求因子个数和因子和

//求因子个数 int Facnt(int n) { int res = 1; for(int i=2;i*i<=n;i++) { if(n%i == 0) { int cnt = 0; do { n /= i; cnt++; }while(n%i==0); res *= (cnt+1); } } if(n > 1) res = 2*res; return res; } //求因子和 int Facsum(int n) { int res = 1; for(int i=2;i*i<=n;

Almost All Divisors(求因子个数及思维)

---恢复内容开始--- We guessed some integer number xx. You are given a list of almost all its divisors. Almost all means that there are all divisors except 11and xx in the list. Your task is to find the minimum possible integer xx that can be the guessed nu

数学题 求因子个数

小C的倍数问题 Accepts: 1990 Submissions: 4931 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description 根据小学数学的知识,我们知道一个正整数x是3的倍数的条件是x每一位加起来的和是3的倍数.反之,如果一个数每一位加起来是3的倍数,则这个数肯定是3的倍数. 现在给定进制P,求有多少个B满足P进制下,一个正整数是B的倍数的

lightoj-1028 - Trailing Zeroes (I)(素数法求因子个数)

1028 - Trailing Zeroes (I) PDF (English) Statistics ForumTime Limit: 2 second(s) Memory Limit: 32 MBWe know what a base of a number is and what the properties are. For example, we use decimal number system, where the base is 10 and we use the symbols

POJ-2992 Divisors---组合数求因子数目

题目链接: https://cn.vjudge.net/problem/POJ-2992 题目大意: 给出组合数Cnk,求出其因子个数,其中n,k不大于431,组合数的值在long long范围内 解题思路: 由于只有431种阶乘,先预处理431中素数,再预处理出每一个阶乘里面所含的素因子的指数,然后对于组合数,直接用素因子指数相减即可. 求出的质因子指数,就可以用定理直接求因子个数. 1 #include<iostream> 2 #include<cstdio> 3 #inclu

(hdu step 2.1.3)Largest prime factor(求一个数的最大质因子的位置)

题目: Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4868 Accepted Submission(s): 1452   Problem Description Everybody knows any number can be combined by the prime number.Now,

求一个数的质因子

private static void prime(int i){ int j = 2; while(true){ while(i%j == 0 && i != j){ System.out.println("Prime num " + j); i = i/j; } if(i == j){ System.out.println("Prime num " + j); break; } j++; } } private static void prime

hdu 6069 Counting Divisors(求因子的个数)

Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 3170    Accepted Submission(s): 1184 Problem Description In mathematics, the function d(n) denotes the number of divisors of

Codeforces546D:Soldier and Number Game(求质因子个数)

Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x