結果

問題 No.300 平方数
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2017-09-29 08:32:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 78,268 KB
実行使用メモリ 10,964 KB
最終ジャッジ日時 2024-04-27 16:04:10
合計ジャッジ時間 1,737 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 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,940 KB
testcase_13 AC 13 ms
10,964 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 WA -
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 11 ms
9,816 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 10 ms
10,604 KB
testcase_29 AC 11 ms
10,600 KB
testcase_30 AC 12 ms
10,616 KB
testcase_31 WA -
testcase_32 AC 9 ms
8,952 KB
testcase_33 AC 5 ms
7,668 KB
testcase_34 AC 11 ms
10,248 KB
testcase_35 AC 9 ms
8,888 KB
testcase_36 AC 10 ms
10,060 KB
testcase_37 AC 8 ms
8,464 KB
testcase_38 AC 4 ms
6,940 KB
testcase_39 AC 10 ms
9,668 KB
testcase_40 AC 10 ms
9,848 KB
testcase_41 AC 5 ms
6,944 KB
testcase_42 AC 4 ms
6,944 KB
testcase_43 WA -
testcase_44 AC 10 ms
8,956 KB
testcase_45 AC 6 ms
6,980 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:42:30: note: within this loop
   42 |     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; }
    }
    if ( X != 1 ) { cout << x << endl; return 0; }
    
    long long ans = 1;
    for ( long long i = 2; i <= 1000000; i++ ) {
        if ( A[i]%2 ) { ans *= i; }
    } 
    cout << ans << endl;
    
    
    return 0;
}
0