結果

問題 No.300 平方数
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2017-09-29 08:43:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 1,000 ms
コード長 864 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 79,724 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2024-04-27 16:04:21
合計ジャッジ時間 1,861 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 16 ms
11,192 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 6 ms
6,944 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 14 ms
9,860 KB
testcase_24 AC 11 ms
8,240 KB
testcase_25 AC 14 ms
10,072 KB
testcase_26 AC 12 ms
10,300 KB
testcase_27 AC 10 ms
7,464 KB
testcase_28 AC 14 ms
10,660 KB
testcase_29 AC 15 ms
10,344 KB
testcase_30 AC 15 ms
10,764 KB
testcase_31 AC 15 ms
10,996 KB
testcase_32 AC 10 ms
8,524 KB
testcase_33 AC 7 ms
6,940 KB
testcase_34 AC 14 ms
10,284 KB
testcase_35 AC 10 ms
8,916 KB
testcase_36 AC 12 ms
9,760 KB
testcase_37 AC 11 ms
8,524 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 13 ms
9,188 KB
testcase_40 AC 11 ms
8,952 KB
testcase_41 AC 8 ms
6,944 KB
testcase_42 AC 3 ms
6,940 KB
testcase_43 AC 15 ms
10,456 KB
testcase_44 AC 11 ms
9,416 KB
testcase_45 AC 7 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:17: warning: iteration 999998 invokes undefined behavior [-Waggressive-loop-optimizations]
   43 |         if ( A[i]%2 ) { ans *= i; }
      |              ~~~^
main.cpp:41:30: note: within this loop
   41 |     for ( long long i = 2; i <= 1000000; i++ ) {
      |                            ~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;


long long A[1000000] = {0};

int main() {
    
    long long X;
    cin >> X;
    
    long long x = X;
    
    for ( long long i = 2; i*i <= x; i++ ) {
        
        int j = 0;
        while ( X%i == 0 ) {
            X /= i;
            j++;
        }
        A[i] = j;
        
        if ( X == 1 ) { break; }
    }
    
    long long ans = 1;
    for ( long long i = 2; i <= 1000000; i++ ) {
        // if ( A[i] ) { cout << i << " " << A[i] << endl; }
        if ( A[i]%2 ) { ans *= i; }
    }
    ans *= X;
    
    cout << ans << endl;
    
    
    return 0;
}
0