HDU 1215 七夕节 数论
生活随笔
收集整理的這篇文章主要介紹了
HDU 1215 七夕节 数论
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
七夕節 Time Limit:1000MS?????Memory Limit:32768KB?????64bit IO Format:%I64d & %I64u
人們紛紛來到告示前,都想知道誰才是自己的另一半.告示如下:?
數字N的因子就是所有比N小又能被N整除的所有正整數,如12的因子有1,2,3,4,6.?
你想知道你的另一半嗎??
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> using namespace std; #define FIN freopen("input.txt","r",stdin); #define INF 0x3f3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef long long LL;LL p[500005];int main() {//FINfor(int i=2;i<=500000;i++)for(int j=i;j<=500000;j+=i)p[j]+=i;LL n,t;scanf("%lld",&t);while(t--){scanf("%lld",&n);printf("%lld\n",p[n]-n+1);}}
Description
七夕節那天,月老來到數字王國,他在城門上貼了一張告示,并且和數字王國的人們說:"你們想知道你們的另一半是誰嗎?那就按照告示上的方法去找吧!"?人們紛紛來到告示前,都想知道誰才是自己的另一半.告示如下:?
數字N的因子就是所有比N小又能被N整除的所有正整數,如12的因子有1,2,3,4,6.?
你想知道你的另一半嗎??
Input
輸入數據的第一行是一個數字T(1<=T<=500000),它表明測試數據的組數.然后是T組測試數據,每組測試數據只有一個數字N(1<=N<=500000).?Output
對于每組測試數據,請輸出一個代表輸入數據N的另一半的編號.?Sample Input
3 2 10 20Sample Output
1 8 22#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> using namespace std; #define FIN freopen("input.txt","r",stdin); #define INF 0x3f3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef long long LL;LL p[500005];int main() {//FINfor(int i=2;i<=500000;i++)for(int j=i;j<=500000;j+=i)p[j]+=i;LL n,t;scanf("%lld",&t);while(t--){scanf("%lld",&n);printf("%lld\n",p[n]-n+1);}}
轉載于:https://www.cnblogs.com/Hyouka/p/5721550.html
總結
以上是生活随笔為你收集整理的HDU 1215 七夕节 数论的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win8 远程桌面时提示凭证不工作问题的
- 下一篇: Android — 使用 SharedP