牛客练习赛25 因数个数和
生活随笔
收集整理的這篇文章主要介紹了
牛客练习赛25 因数个数和
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接
題目描述
q次詢問,每次給一個x,問1到x的因數(shù)個數(shù)的和。
輸入描述:
第一行一個正整數(shù)q ;
接下來q行,每行一個正整數(shù) x
輸出描述:
共q行,每行一個正整數(shù)表示答案
示例1
輸入
4 1 2 3 10輸出
1 3 5 27說明
1的因數(shù)有12的因數(shù)有1,23的因數(shù)有1,3以此類推 備注: 1<=q<=10 ,1<= x<=109AC
#include <iostream> #include <stdio.h> #include <map> #include <vector> #include <bits/stdc++.h> #include <algorithm> #define N 100005 #define ll long long using namespace std;int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endifint t;scanf("%d", &t);while (t--) {int n;scanf("%d", &n);ll ans = 0;for (int i = 1; i <= n; ++i) {int tar = n / i; // 當前約數(shù)int l = i;int r = n / tar; // 約數(shù)為tar的最右邊的位置ans += (r - l + 1) * tar; //區(qū)間乘以tari = r;} printf("%lld\n", ans);}return 0; }總結(jié)
以上是生活随笔為你收集整理的牛客练习赛25 因数个数和的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU Problem - 5938 F
- 下一篇: Codeforces Round #50